/*
Demo of the headless approach where we must supply the array length
964174
public static void headlessDemo() {
        System.out.println("Compressing arrays with minimal header...");
        int[] uncompressed1 = {1,2,1,3,1};
        int[] uncompressed2 = {3,2,4,6,1};

        int[] compressed = new int[uncompressed1.length+uncompressed2.length+1024];

        SkippableIntegerCODEC codec = new SkippableComposition(new BinaryPacking(), new VariableByte());

        // compressing
        IntWrapper outPos = new IntWrapper();

        IntWrapper previous = new IntWrapper();

        codec.headlessCompress(uncompressed1,new IntWrapper(),uncompressed1.length,compressed,outPos);
        int length1 = outPos.get() - previous.get();
        previous = new IntWrapper(outPos.get());
        codec.headlessCompress(uncompressed2,new IntWrapper(),uncompressed2.length,compressed,outPos);
        int length2 = outPos.get() - previous.get();



        compressed = Arrays.copyOf(compressed,length1 + length2);
        System.out.println("compressed unsorted integers from "+uncompressed1.length*4+"B to "+length1*4+"B");
        System.out.println("compressed unsorted integers from "+uncompressed2.length*4+"B to "+length2*4+"B");
        System.out.println("Total compressed output "+compressed.length);

        int[] recovered1 = new int[uncompressed1.length];
        int[] recovered2 = new int[uncompressed1.length];
        IntWrapper inPos = new IntWrapper();
        System.out.println("Decoding first array starting at pos = "+inPos);
        codec.headlessUncompress(compressed,inPos, compressed.length, recovered1, new IntWrapper(0), uncompressed1.length);
        System.out.println("Decoding second array starting at pos = "+inPos);
        codec.headlessUncompress(compressed,inPos, compressed.length, recovered2, new IntWrapper(0), uncompressed2.length);
        if(!Arrays.equals(uncompressed1,recovered1)) throw new RuntimeException("First array does not match.");
        if(!Arrays.equals(uncompressed2,recovered2)) throw new RuntimeException("Second array does not match.");
        System.out.println("The arrays match, your code is probably ok.");

    }
160622
function(array, maximumLength) {
    var currentNode = array.length - 2;
    var currentDepth;
    for (currentDepth = 1;
         (currentDepth < (maximumLength - 1)) && (currentNode > 1);
         currentDepth++) {
      currentNode =  first (array, currentNode - 1, 0);
    }

    return currentNode;
  }
368365
function(array) {
    var length = array.length;

    array[0] += array[1];

    var headNode, tailNode, topNode, temp;
    for (headNode = 0, tailNode = 1, topNode = 2;
         tailNode < (length - 1);
         tailNode++) {
      if ((topNode >= length) || (array[headNode] < array[topNode])) {
        temp = array[headNode];
        array[headNode++] = tailNode;
      } else {
        temp = array[topNode++];
      }

      if ((topNode >= length) ||
          ((headNode < tailNode) && (array[headNode] < array[topNode]))) {
        temp += array[headNode];
        array[headNode++] = tailNode + length;
      } else {
        temp += array[topNode++];
      }

      array[tailNode] = temp;
    }
  }
32677
function header(length) {
                var res = [0x09, 0x09, 0x00, 0x00];
                res.push((length & 0x000000FF) >> 0);
                res.push((length & 0x0000FF00) >> 8);
                res.push((length & 0x00FF0000) >> 16);
                res.push((length & 0xFF000000) >> 24);
                return new Buffer(res);
            }
800295
function(array, n) {
      var ret = [];
      var sz = _.size(array);

      if (n <= 0) return [];
      if (n === 1) return array;

      for(var index = 0; index < sz; index += n) {
        ret.push(array[index]);
      }

      return ret;
    }
254767
function strArrayToObj (array) {
  return array && array.reduce(function(o, v) {
      o[v] = true;
      return o;
    }, {});
}
1013800
private static int search(int value, int[] array, int start, int length)
    {
        int power = 1 << getHighBit(length);
        int extra = length - power;
        int probe = power;
        int index = start;

        if (value >= array[index + extra]) {
            index += extra;
        }

        while (probe > 1) {
            probe >>= 1;

            if (value >= array[index + probe]) {
                index += probe;
            }
        }

        return index;
    }
316183
function(arrayBuffer, sliceSize) {
		var segments= [],
			fi = 0;
		while(fi * sliceSize < arrayBuffer.byteLength){
			segments.push(arrayBuffer.slice(fi * sliceSize, (fi + 1) * sliceSize));
			fi++;
		}
		return segments;
	}
242301
function ArrayType (data, length) {
    if (!(this instanceof ArrayType)) {
      return new ArrayType(data, length)
    }
    debug('creating new array instance')
    ArrayIndex.call(this)
    var item_size = ArrayType.BYTES_PER_ELEMENT
    if (0 === arguments.length) {
      // new IntArray()
      // use the "fixedLength" if provided, otherwise throw an Error
      if (fixedLength > 0) {
        this.length = fixedLength
        this.buffer = new Buffer(this.length * item_size)
      } else {
        throw new Error('A "length", "array" or "buffer" must be passed as the first argument')
      }
    } else if ('number' == typeof data) {
      // new IntArray(69)
      this.length = data
      this.buffer = new Buffer(this.length * item_size)
    } else if (isArray(data)) {
      // new IntArray([ 1, 2, 3, 4, 5 ], {len})
      // use optional "length" if provided, otherwise use "fixedLength, otherwise
      // use the Array's .length
      var len = 0
      if (null != length) {
        len = length
      } else if (fixedLength > 0) {
        len = fixedLength
      } else {
        len = data.length
      }
      if (data.length < len) {
        throw new Error('array length must be at least ' + len + ', got ' + data.length)
      }
      this.length = len
      this.buffer = new Buffer(len * item_size)
      for (var i = 0; i < len; i++) {
        this[i] = data[i]
      }
    } else if (Buffer.isBuffer(data)) {
      // new IntArray(Buffer(8))
      var len = 0
      if (null != length) {
        len = length
      } else if (fixedLength > 0) {
        len = fixedLength
      } else {
        len = data.length / item_size | 0
      }
      var expectedLength = item_size * len
      this.length = len
      if (data.length != expectedLength) {
        if (data.length < expectedLength) {
          throw new Error('buffer length must be at least ' + expectedLength + ', got ' + data.length)
        } else {
          debug('resizing buffer from %d to %d', data.length, expectedLength)
          data = data.slice(0, expectedLength)
        }
      }
      this.buffer = data
    }
  }
1138295
private static int[] mstPartition(double[][] matrix) {
    final int n = matrix.length;
    int[] edges = PrimsMinimumSpanningTree.processDense(matrix);
    // Note: Prims does *not* yield edges sorted by edge length!
    double meanlength = thresholdLength(matrix, edges);
    int[] idx = new int[n], best = new int[n], sizes = new int[n];
    int bestsize = -1;
    double bestlen = 0;
    for(int omit = n - 2; omit > 0; --omit) {
      final double len = edgelength(matrix, edges, omit);
      if(len < meanlength) {
        continue;
      }
      omitEdge(edges, idx, sizes, omit);
      // Finalize array:
      int minsize = n;
      for(int i = 0; i < n; i++) {
        int j = idx[i] = follow(i, idx);
        if(j == i && sizes[i] < minsize) {
          minsize = sizes[i];
        }
      }
      if(minsize > bestsize || (minsize == bestsize && len > bestlen)) {
        bestsize = minsize;
        bestlen = len;
        System.arraycopy(idx, 0, best, 0, n);
      }
    }
    return best;
  }
67323
function getLengthOfCombinedArrays(name) {
    let length = 0;
    let arraySpec;
    for (let ii = 0; ii < arrayOfArrays.length; ++ii) {
      const arrays = arrayOfArrays[ii];
      const arrayInfo = arrays[name];
      const array = getArray(arrayInfo);
      length += array.length;
      if (!arraySpec || arrayInfo.data) {
        arraySpec = arrayInfo;
      }
    }
    return {
      length: length,
      spec: arraySpec,
    };
  }
597177
def header(self, array):
        

        self._check_row_size(array)
        self._header = map(str, array)
995531
function arraySampleSize(array, n) {
      return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
    }
1329187
protected void fillArray(final short[] array) {
    int pos = 0;
    int base = 0;
    for (int k = 0; k < bitmap.length; ++k) {
      long bitset = bitmap[k];
      while (bitset != 0) {
        array[pos++] = (short) (base + numberOfTrailingZeros(bitset));
        bitset &= (bitset - 1);
      }
      base += 64;
    }
  }
1086129
function (array) {
        var value;
        var ArrayConstructor = this.vertexCount > 0xffff
            ? vendor.Uint32Array : vendor.Uint16Array;
        // Convert 2d array to flat
        if (array[0] && (array[0].length)) {
            var n = 0;
            var size = 3;

            value = new ArrayConstructor(array.length * size);
            for (var i = 0; i < array.length; i++) {
                for (var j = 0; j < size; j++) {
                    value[n++] = array[i][j];
                }
            }
        }
        else {
            value = new ArrayConstructor(array);
        }

        this.indices = value;
    }
303174
private int[] determinePower2Alpha_Buckets_Sarray_Sptrmap(int q) {
        int strLen = length;
        int exp2 = kbs_getExp_Ulong(2, alphabet.size);
        if (exp2 < 0) {
            throw new RuntimeException("value out of bounds");
        }
        int[] buckets = determinePower2Alpha_Buckets_Sarray(q);
        this.sufPtrMap = new int[strLen + 2 * q + 1];
        int mappedUcharArray = 0;
        int hashCode = 0;
        int j;
        for (j = 0; j < q; j++) {
            hashCode = hashCode << exp2;
            hashCode += seq[start + mappedUcharArray + j];
        }
        int tempModulo = 0;
        tempModulo = ~tempModulo;
        tempModulo = tempModulo << (exp2 * (q - 1));
        tempModulo = ~tempModulo;
        mappedUcharArray += q;
        for (j = 0; j < strLen - 1; j++) {
            sufPtrMap[j] = (buckets[hashCode + 1]) - 1;
            hashCode = hashCode & tempModulo;
            hashCode = hashCode << exp2;
            hashCode = hashCode | seq[start + mappedUcharArray];
            mappedUcharArray++;
        }
        sufPtrMap[j] = buckets[hashCode];
        int beginPtr = -1;
        for (j = strLen; j <= strLen + 2 * q; j++) {
            sufPtrMap[j] = beginPtr--;
        }

        return buckets;
    }
1031640
function (arr) {
    var out = [], bl = sjcl.bitArray.bitLength(arr), i, tmp;
    for (i=0; i<bl/8; i++) {
      if ((i&3) === 0) {
        tmp = arr[i/4];
      }
      out.push(tmp >>> 24);
      tmp <<= 8;
    }
    return out;
  }