CountMinSketch(int depth, int width, long size, long[] hashA, long[][] table) { this.depth = depth; this.width = width; this.eps = 2.0 / width; this.confidence = 1 - 1 / Math.pow(2, depth); this.hashA = hashA; this.table = table; Preconditions.checkState(size >= 0, "The size cannot be smaller than ZER0: " + size); this.size = size; }
public static int decode(ByteBuffer buf) { int v = buf.get(); int z = 0x7f & v; int shift = 7; while ((v & 0x80) != 0) { Preconditions.checkState(shift <= 28); v = buf.get(); z += (v & 0x7f) << shift; shift += 7; } return z; }
public static void encode(ByteBuffer buf, int n) { int k = 0; while (n < 0 || n > 0x7f) { byte b = (byte) (0x80 | (0x7f & n)); buf.put(b); n = n >>> 7; k++; Preconditions.checkState(k < 6); } buf.put((byte) n); }
/** * @return the first Group in this set */ public TDigest.Group first() { Preconditions.checkState(size > 0, "No first element of empty set"); if (left == null) { return leaf; } else { return left.first(); } }
public TDigest.Group last() { Preconditions.checkState(size > 0, "Cannot find last element of empty set"); if (size == 1) { return leaf; } else { return right.last(); } }
public void checkBalance() { if (left != null) { Preconditions.checkState(Math.abs(left.depth() - right.depth()) < 2, "Imbalanced"); int l = left.depth(); int r = right.depth(); Preconditions.checkState(depth == Math.max(l, r) + 1, "Depth doesn't match children"); Preconditions.checkState(size == left.size + right.size, "Sizes don't match children"); Preconditions.checkState(count == left.count + right.count, "Counts don't match children"); Preconditions.checkState(leaf.compareTo(right.first()) == 0, "Split is wrong %.5d != %.5d or %d != %d", leaf.mean(), right.first().mean(), leaf.id(), right.first().id()); left.checkBalance(); right.checkBalance(); } }
public void addColumnMinMaxValue() throws Exception { Preconditions.checkState(_columnMinMaxValueGeneratorMode != ColumnMinMaxValueGeneratorMode.NONE); Schema schema = _segmentMetadata.getSchema(); // Process time column String timeColumnName = schema.getTimeColumnName(); if (timeColumnName != null) { addColumnMinMaxValueForColumn(timeColumnName); } if (_columnMinMaxValueGeneratorMode == ColumnMinMaxValueGeneratorMode.TIME) { saveMetadata(); return; } // Process dimension columns for (String dimensionColumnName : schema.getDimensionNames()) { addColumnMinMaxValueForColumn(dimensionColumnName); } if (_columnMinMaxValueGeneratorMode == ColumnMinMaxValueGeneratorMode.NON_METRIC) { saveMetadata(); return; } // Process metric columns for (String metricColumnName : schema.getMetricNames()) { addColumnMinMaxValueForColumn(metricColumnName); } saveMetadata(); }
public void remove(TDigest.Group base) { Preconditions.checkState(size > 0, "Cannot remove from empty set"); if (size == 1) { Preconditions.checkArgument(base.compareTo(leaf) == 0, "Element %s not found", base);
public static void encode(ByteBuffer buf, int n) { int k = 0; while (n < 0 || n > 0x7f) { byte b = (byte) (0x80 | (0x7f & n)); buf.put(b); n = n >>> 7; k++; Preconditions.checkState(k < 6); } buf.put((byte) n); }
public static int decode(ByteBuffer buf) { int v = buf.get(); int z = 0x7f & v; int shift = 7; while ((v & 0x80) != 0) { Preconditions.checkState(shift <= 28); v = buf.get(); z += (v & 0x7f) << shift; shift += 7; } return z; }
public static void encode(ByteBuffer buf, int n) { int k = 0; while (n < 0 || n > 0x7f) { byte b = (byte) (0x80 | (0x7f & n)); buf.put(b); n = n >>> 7; k++; Preconditions.checkState(k < 6); } buf.put((byte) n); }
public static int decode(ByteBuffer buf) { int v = buf.get(); int z = 0x7f & v; int shift = 7; while ((v & 0x80) != 0) { Preconditions.checkState(shift <= 28); v = buf.get(); z += (v & 0x7f) << shift; shift += 7; } return z; }
/** * @return the first Group in this set */ public TDigest.Group first() { Preconditions.checkState(size > 0, "No first element of empty set"); if (left == null) { return leaf; } else { return left.first(); } }
public TDigest.Group last() { Preconditions.checkState(size > 0, "Cannot find last element of empty set"); if (size == 1) { return leaf; } else { return right.last(); } }
/** * @return the first Group in this set */ public TDigest.Group first() { Preconditions.checkState(size > 0, "No first element of empty set"); if (left == null) { return leaf; } else { return left.first(); } }
public TDigest.Group last() { Preconditions.checkState(size > 0, "Cannot find last element of empty set"); if (size == 1) { return leaf; } else { return right.last(); } }
public void checkBalance() { if (left != null) { Preconditions.checkState(Math.abs(left.depth() - right.depth()) < 2, "Imbalanced"); int l = left.depth(); int r = right.depth(); Preconditions.checkState(depth == Math.max(l, r) + 1, "Depth doesn't match children"); Preconditions.checkState(size == left.size + right.size, "Sizes don't match children"); Preconditions.checkState(count == left.count + right.count, "Counts don't match children"); Preconditions.checkState(leaf.compareTo(right.first()) == 0, "Split is wrong %.5d != %.5d or %d != %d", leaf.mean(), right.first().mean(), leaf.id(), right.first().id()); left.checkBalance(); right.checkBalance(); } }
public void checkBalance() { if (left != null) { Preconditions.checkState(Math.abs(left.depth() - right.depth()) < 2, "Imbalanced"); int l = left.depth(); int r = right.depth(); Preconditions.checkState(depth == Math.max(l, r) + 1, "Depth doesn't match children"); Preconditions.checkState(size == left.size + right.size, "Sizes don't match children"); Preconditions.checkState(count == left.count + right.count, "Counts don't match children"); Preconditions.checkState(leaf.compareTo(right.first()) == 0, "Split is wrong %.5d != %.5d or %d != %d", leaf.mean(), right.first().mean(), leaf.id(), right.first().id()); left.checkBalance(); right.checkBalance(); } }
public void remove(TDigest.Group base) { Preconditions.checkState(size > 0, "Cannot remove from empty set"); if (size == 1) { Preconditions.checkArgument(base.compareTo(leaf) == 0, "Element %s not found", base);
public void remove(TDigest.Group base) { Preconditions.checkState(size > 0, "Cannot remove from empty set"); if (size == 1) { Preconditions.checkArgument(base.compareTo(leaf) == 0, "Element %s not found", base);