From 111c91c70de448441520441f0d79c58f01980c7d Mon Sep 17 00:00:00 2001 From: Jordi Baylina Date: Thu, 30 Jan 2020 07:25:48 +0100 Subject: [PATCH] bigarray --- src/bigarray.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ src/compiler.js | 21 +++++++++--------- src/ctx.js | 7 +++--- 3 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 src/bigarray.js diff --git a/src/bigarray.js b/src/bigarray.js new file mode 100644 index 0000000..15a43a3 --- /dev/null +++ b/src/bigarray.js @@ -0,0 +1,59 @@ +const SUBARRAY_SIZE = 0x10000; + +const BigArrayHandler = { + get: function(obj, prop) { + if (!isNaN(prop)) { + return obj.getElement(prop); + } else return obj[prop]; + }, + set: function(obj, prop, value) { + if (!isNaN(prop)) { + return obj.setElement(prop, value); + } else { + obj[prop] = value; + return true; + } + } +}; + +class _BigArray { + constructor (initSize) { + this.length = initSize || 0; + this.arr = []; + + for (let i=0; i= this.length) this.length = idx+1; + return true; + } +} + +class BigArray { + constructor( initSize ) { + const obj = new _BigArray(initSize); + const extObj = new Proxy(obj, BigArrayHandler); + return extObj; + } +} + +module.exports = BigArray; diff --git a/src/compiler.js b/src/compiler.js index 9e8e955..d7c31e6 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -26,6 +26,7 @@ const Ctx = require("./ctx"); const ZqField = require("fflib").ZqField; const utils = require("./utils"); const buildR1cs = require("./r1csfile").buildR1cs; +const BigArray = require("./bigarray"); module.exports = compile; @@ -124,7 +125,7 @@ function classifySignals(ctx) { } // First classify the signals - for (let s in ctx.signals) { + for (let s=0; s0) { - let nextPossibleConstraints = {}; - for (let i in possibleConstraints) { + let nextPossibleConstraints = new BigArray(); + for (let i=0; i=0) { lSignal = ctx.signals[lSignal.e]; @@ -462,7 +463,7 @@ is converted to A B C */ - +/* function buildConstraints(ctx) { const res = []; @@ -489,7 +490,7 @@ function buildConstraints(ctx) { return res; } - +*/ function buildSyms(ctx, strm) { let nSyms; diff --git a/src/ctx.js b/src/ctx.js index c7b6b70..932e0ab 100644 --- a/src/ctx.js +++ b/src/ctx.js @@ -1,4 +1,5 @@ const bigInt = require("big-integer"); +const BigArray = require("./bigarray.js"); class TableName { @@ -103,11 +104,11 @@ module.exports = class Ctx { this.COUNTED = 0x20; this.scopes = [{}]; - this.signals = []; + this.signals = new BigArray(); this.currentComponent= -1; - this.constraints= []; - this.components= []; + this.constraints= new BigArray(); + this.components= new BigArray(); this.templates= {}; this.functions= {}; this.functionParams= {};