<commit_before>var Tree = require('./tree'),
  crypto = require('crypto'),
  helpers = require('./helpers'),
  Big = require('big.js');

// monkey patch Big to disable exponent notation when calling toSring
// exponent notation is not allowed by specification
Big.prototype.toString = helpers.bigToString;


function big(val) {
  return (val instanceof Big) ? val : new Big(val);
}

function sha256 (data) {
  return crypto.createHash('sha256').update(data).digest('hex');
}

function nonce () {
  // @TODO: 128 bits of randomness!?
  // Javascript floating numbers are represented with 64 bit IIRC
  // The following code will probably make cryptographers want to tear their
  // eyes out.
  var randomness = Math.random() + '' + Math.random();
  var hex = sha256(randomness);
  // 128 bits can be represented with 32 hex characters
  return hex.substr(0, 32);
}

// http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object
function clone (obj) {
  if (null === obj || "object" != typeof obj) return obj;
  var copy = obj.constructor();
  for (var attr in obj) {
    if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
  }
  return copy;
}

function combine_nodes (left_node, right_node) {
  var n = {};
  n.sum = big(left_node.sum).plus(right_node.sum);
  n.hash = sha256(n.sum + '' + left_node.hash + '' + right_node.hash);
  return n;
}

function generate_leaf_hash (user, sum, nonce) {
  return sha256(user + '|' + big(sum) + '|' + nonce);
}

// @todo: since all nodes are at same tree level, this might
// leak information about number of users. randomize tree structure!?
// add fake nodes with 0 balance? maybe all right leaf node should be a dummy user?
function generate_complete_tree (accounts) {
  var mode = 'default';

  // first account has nonce set triggers deterministic mode
  if (accounts[0].nonce) {<commit_msg>Use '|' to separate in nodecombiner<commit_after>var Tree = require('./tree'),
  crypto = require('crypto'),
  helpers = require('./helpers'),
  Big = require('big.js');

// monkey patch Big to disable exponent notation when calling toSring
// exponent notation is not allowed by specification
Big.prototype.toString = helpers.bigToString;


function big(val) {
  return (val instanceof Big) ? val : new Big(val);
}

function sha256 (data) {
  return crypto.createHash('sha256').update(data).digest('hex');
}

function nonce () {
  // @TODO: 128 bits of randomness!?
  // Javascript floating numbers are represented with 64 bit IIRC
  // The following code will probably make cryptographers want to tear their
  // eyes out.
  var randomness = Math.random() + '' + Math.random();
  var hex = sha256(randomness);
  // 128 bits can be represented with 32 hex characters
  return hex.substr(0, 32);
}

// http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object
function clone (obj) {
  if (null === obj || "object" != typeof obj) return obj;
  var copy = obj.constructor();
  for (var attr in obj) {
    if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
  }
  return copy;
}

function combine_nodes (left_node, right_node) {
  var n = {};
  n.sum = big(left_node.sum).plus(right_node.sum);
  n.hash = sha256(n.sum + '|' + left_node.hash + '|' + right_node.hash);
  return n;
}

function generate_leaf_hash (user, sum, nonce) {
  return sha256(user + '|' + big(sum) + '|' + nonce);
}

// @todo: since all nodes are at same tree level, this might
// leak information about number of users. randomize tree structure!?
// add fake nodes with 0 balance? maybe all right leaf node should be a dummy user?
function generate_complete_tree (accounts) {
  var mode = 'default';

  // first account has nonce set triggers deterministic mode
  if (accounts[0].nonce) {
{'fraction_non_alphanumeric': 0.13399041022908897, 'fraction_numerical': 0.019179541822056473, 'mean_word_length': 3.8639896373056994, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7098929', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1159, 'n_words': 386}