From 1e2fb12631be896be9aa3b58ca6e941b6e30d1f5 Mon Sep 17 00:00:00 2001 From: Jordi Baylina Date: Thu, 30 Jul 2020 05:04:15 +0200 Subject: [PATCH] BigArray in code --- ports/c/builder.js | 6 +++++- src/bigarray.js | 6 ++++-- src/build.js | 8 ++++---- src/streamfromarray_txt.js | 4 ++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ports/c/builder.js b/ports/c/builder.js index 8bbe44b..cf60c1e 100644 --- a/ports/c/builder.js +++ b/ports/c/builder.js @@ -484,6 +484,7 @@ class BuilderC { code.push("// Constants"); code.push(`FrElement _constants[${self.constants.length}] = {`); for (let i=0; i0 ? "," : " ") + "{" + number2Code(self.constants[i]) + "}"); } code.push("};"); @@ -561,6 +562,7 @@ class BuilderC { code.push("// Components"); code.push(`Circom_Component _components[${this.components.length}] = {`); for (let i=0; i0 ? " ," : " "; code.push(`${sep}{${c.hashMapName}, ${c.entryTableName}, ${c.functionName}, ${c.nInSignals}, ${c.newThread}}`); @@ -573,6 +575,7 @@ class BuilderC { code.push(`u32 _mapIsInput[${this.mapIsInput.length}] = {`); let line = ""; for (let i=0; i0 ? ", " : " "; line += toHex(this.mapIsInput[i]); if (((i+1) % 64)==0) { @@ -596,6 +599,7 @@ class BuilderC { code.push(`int _wit2sig[${this.wit2sig.length}] = {`); let line = ""; for (let i=0; i0 ? "," : " "; line += this.wit2sig[i]; if (((i+1) % 64) == 0) { @@ -628,7 +632,7 @@ class BuilderC { build() { - const code=[]; + const code=new BigArray(); this._buildHeader(code); this._buildSizes(code); this._buildConstants(code); diff --git a/src/bigarray.js b/src/bigarray.js index ce68aa9..517e9f3 100644 --- a/src/bigarray.js +++ b/src/bigarray.js @@ -26,8 +26,10 @@ class _BigArray { } return this; } - push (element) { - this.setElement (this.length, element); + push () { + for (let i=0; i=0) continue; // If has an alias, continue.. assert(typeof outIdx != "undefined", `Signal ${i} does not have index`); diff --git a/src/streamfromarray_txt.js b/src/streamfromarray_txt.js index 4624f0a..41040e5 100644 --- a/src/streamfromarray_txt.js +++ b/src/streamfromarray_txt.js @@ -1,4 +1,4 @@ - +const BigArray = require("./bigArray"); const Readable = require("stream").Readable; module.exports = function streamFromArrayTxt(ma) { @@ -22,7 +22,7 @@ module.exports = function streamFromArrayTxt(ma) { function getFirstIdx(ma) { - if (!Array.isArray(ma)) return []; + if (typeof ma.push !== "function" ) return []; return [0, ...getFirstIdx(ma[0])]; }