Return the given byte array as a CpcSketch on the Java heap.
@param byteArray the given byte array
@param seed the seed used to create the original sketch from which the byte array was derived.
@return the given byte array as a CpcSketch on the Java heap.
977072
public static CpcSketch heapify(final byte[] byteArray, final long seed) {
    final Memory mem = Memory.wrap(byteArray);
    return heapify(mem, seed);
  }
440450
public final int hash(ByteBuffer buf, int seed) {
    final int hash = hash(buf, buf.position(), buf.remaining(), seed);
    buf.position(buf.limit());
    return hash;
  }
1349653
public Random getNewRandomInstance(long seed) {
        try {
            Random t = (Random) randomClass.newInstance();
            if (t.getStatePointer() != null) {
                // TODO: attach this thing to deallocator
                // if it's stateless random - we just don't care then
            }
            t.setSeed(seed);
            return t;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
836709
static void refreshKXP(final CpcSketch sketch, final long[] bitMatrix) {
    final int k = (1 << sketch.lgK);

    // for improved numerical accuracy, we separately sum the bytes of the U64's
    final double[] byteSums = new double[8];

    for (int j = 0; j < 8; j++) { byteSums[j] = 0.0; }

    for (int i = 0; i < k; i++) {
      long row = bitMatrix[i];
      for (int j = 0; j < 8; j++) {
        final int byteIdx = (int) (row & 0XFFL);
        byteSums[j] += kxpByteLookup[byteIdx];
        row >>>= 8;
      }
    }

    double total = 0.0;

    for (int j = 7; j-- > 0; ) { // the reverse order is important
      final double factor = invPow2(8 * j); // pow(256, -j) == pow(2, -8 * j);
      total += factor * byteSums[j];
    }
    sketch.kxp = total;
  }
283991
public static void seed(long seed) {
        System.out.println("SEED="+seed);
        Prng.seed = seed;
        curRandom.setSeed(seed);
    }
170428
public static long[] hashToLongs(final byte[] data, final long seed) {
    if ((data == null) || (data.length == 0)) {
      return null;
    }
    return hash(data, seed);
  }
1148282
public static SingleItemSketch heapify(final Memory mem, final long seed) {
    final long memPre0 = mem.getLong(0);
    checkDefaultBytes0to5(memPre0);
    final short seedHashIn = mem.getShort(6);
    final short seedHashCk = computeSeedHash(seed);
    checkSeedHashes(seedHashIn, seedHashCk);
    return new SingleItemSketch(mem.getLong(8), seed);
  }
182057
private static String byteArrayToHexString(byte[] byteArray) {
		StringBuilder result = new StringBuilder();
		
		for (byte b : byteArray) {
			result.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
		}
		
		return result.toString();
	}
32030
public static ByteRangeRandomizer aNewByteRangeRandomizer(final Byte min, final Byte max, final long seed) {
        return new ByteRangeRandomizer(min, max, seed);
    }
679001
static HeapUpdateDoublesSketch copyToHeap(final DoublesSketch sketch) {
    final HeapUpdateDoublesSketch qsCopy;
    qsCopy = HeapUpdateDoublesSketch.newInstance(sketch.getK());
    qsCopy.putN(sketch.getN());
    qsCopy.putMinValue(sketch.getMinValue());
    qsCopy.putMaxValue(sketch.getMaxValue());
    qsCopy.putBaseBufferCount(sketch.getBaseBufferCount());
    qsCopy.putBitPattern(sketch.getBitPattern());

    if (sketch.isCompact()) {
      final int combBufItems = Util.computeCombinedBufferItemCapacity(sketch.getK(), sketch.getN());
      final double[] combBuf = new double[combBufItems];
      qsCopy.putCombinedBuffer(combBuf);
      final DoublesSketchAccessor sketchAccessor = DoublesSketchAccessor.wrap(sketch);
      final DoublesSketchAccessor copyAccessor = DoublesSketchAccessor.wrap(qsCopy);
      // start with BB
      copyAccessor.putArray(sketchAccessor.getArray(0, sketchAccessor.numItems()),
              0, 0, sketchAccessor.numItems());

      long bitPattern = sketch.getBitPattern();
      for (int lvl = 0; bitPattern != 0L; ++lvl, bitPattern >>>= 1) {
        if ((bitPattern & 1L) > 0L) {
          sketchAccessor.setLevel(lvl);
          copyAccessor.setLevel(lvl);
          copyAccessor.putArray(sketchAccessor.getArray(0, sketchAccessor.numItems()),
                  0, 0, sketchAccessor.numItems());
        }
      }
    } else {
      final double[] combBuf = sketch.getCombinedBuffer();
      qsCopy.putCombinedBuffer(Arrays.copyOf(combBuf, combBuf.length));
    }
    return qsCopy;
  }
807448
static DoublesUnionImpl heapifyInstance(final DoublesSketch sketch) {
    final int k = sketch.getK();
    final DoublesUnionImpl union = new DoublesUnionImpl(k);
    union.maxK_ = k;
    union.gadget_ = copyToHeap(sketch);
    return union;
  }
628153
private byte[] pbkdf2(char[] password, byte[] salt) {
        try {
            PBEKeySpec spec = new PBEKeySpec(password, salt, PBKDF2_ITERATIONS, HASH_BYTE_SIZE * 8);
            SecretKeyFactory skf = SecretKeyFactory.getInstance(PBKDF2_ALGORITHM);
            return skf.generateSecret(spec).getEncoded();
        } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
            throw SeedException.wrap(e, CryptoErrorCode.UNEXPECTED_EXCEPTION);
        }
    }
628622
public static final ISID createRandom (final long seed) {

        // TODO: Implement Qualifier
        final Random rand = new Random(seed);

        final ISID isid = new ISID(Format.RANDOM, Constants.RESERVED_BYTE, (short) rand.nextInt(), (byte) rand.nextInt(), (short) 0);

        return isid;
    }
1219062
static CompactSketch heapifyInstance(final Memory srcMem, final long seed) {
    final short memSeedHash = (short) extractSeedHash(srcMem);
    final short computedSeedHash = computeSeedHash(seed);
    checkSeedHashes(memSeedHash, computedSeedHash);

    final int preLongs = extractPreLongs(srcMem);
    final boolean empty = PreambleUtil.isEmpty(srcMem);
    int curCount = 0;
    long thetaLong = Long.MAX_VALUE;
    long[] cache = new long[0];

    if (preLongs == 1) {
      if (!empty) { //singleItem
        return new SingleItemSketch(srcMem.getLong(8), memSeedHash);
      }
      //else empty
    } else { //preLongs > 1
      curCount = extractCurCount(srcMem);
      cache = new long[curCount];
      if (preLongs == 2) {
        srcMem.getLongArray(16, cache, 0, curCount);
      } else { //preLongs == 3
        srcMem.getLongArray(24, cache, 0, curCount);
        thetaLong = extractThetaLong(srcMem);
      }
    }
    return new HeapCompactOrderedSketch(cache, empty, memSeedHash, curCount, thetaLong);
  }
179282
public static Point getSize(byte[] byteArray, int offset, int length) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeByteArray(byteArray, offset, length, options);
        int width = options.outWidth;
        int height = options.outHeight;
        return new Point(width, height);
    }
103277
public static void sortDescending(byte[] byteArray) {
        int index = 0;
        byte value = 0;
        
        for(int i = 1; i < byteArray.length; i++) {
            index = i;
            value = byteArray[index];
            
            while(index > 0 && value > byteArray[index - 1]) {
                byteArray[index] = byteArray[index - 1];
                
                index--;
            }
            
            byteArray[index] = value;
        }
    }
804011
public static synchronized boolean randomize(byte[] seed) throws AssertFailException {
        Preconditions.checkArgument(seed.length == 32 || seed == null);

        ByteBuffer byteBuff = nativeECDSABuffer.get();
        if (byteBuff == null || byteBuff.capacity() < seed.length) {
            byteBuff = ByteBuffer.allocateDirect(seed.length);
            byteBuff.order(ByteOrder.nativeOrder());
            nativeECDSABuffer.set(byteBuff);
        }
        byteBuff.rewind();
        byteBuff.put(seed);

        w.lock();
        try {
            return secp256k1_context_randomize(byteBuff, Secp256k1Context.getContext()) == 1;
        } finally {
            w.unlock();
        }
    }