List of usage examples for java.lang Long SIZE
int SIZE
To view the source code for java.lang Long SIZE.
Click Source Link
From source file:com.moz.fiji.schema.FormattedEntityId.java
/** * Decode a byte array containing an hbase row key into an ordered list corresponding to * the key format in the layout file./*from ww w .j a v a2 s . c om*/ * * @param format The row key format as specified in the layout file. * @param hbaseRowKey A byte array containing the hbase row key. * @return An ordered list of component values in the key. */ private static List<Object> makeFijiRowKey(RowKeyFormat2 format, byte[] hbaseRowKey) { if (hbaseRowKey.length == 0) { throw new EntityIdException("Invalid hbase row key"); } List<Object> fijiRowKey = new ArrayList<Object>(); // skip over the hash int pos = format.getSalt().getHashSize(); // we are suppressing materialization, so the components cannot be retrieved. int fijiRowElem = 0; if (format.getSalt().getSuppressKeyMaterialization()) { if (pos < hbaseRowKey.length) { throw new EntityIdException("Extra bytes in key after hash when materialization is" + "suppressed"); } return null; } ByteBuffer buf; while (fijiRowElem < format.getComponents().size() && pos < hbaseRowKey.length) { switch (format.getComponents().get(fijiRowElem).getType()) { case STRING: // Read the row key until we encounter a Null (0) byte or end. int endpos = pos; while (endpos < hbaseRowKey.length && (hbaseRowKey[endpos] != (byte) 0)) { endpos += 1; } String str = null; try { str = new String(hbaseRowKey, pos, endpos - pos, "UTF-8"); } catch (UnsupportedEncodingException e) { LOG.error(e.toString()); throw new EntityIdException(String.format("UnsupportedEncoding for component %d", fijiRowElem)); } fijiRowKey.add(str); pos = endpos + 1; break; case INTEGER: // Toggle highest order bit to return to original 2's complement. hbaseRowKey[pos] = (byte) ((int) hbaseRowKey[pos] ^ (int) Byte.MIN_VALUE); try { buf = ByteBuffer.wrap(hbaseRowKey, pos, Integer.SIZE / Byte.SIZE); } catch (IndexOutOfBoundsException e) { throw new EntityIdException("Malformed hbase Row Key"); } fijiRowKey.add(Integer.valueOf(buf.getInt())); pos = pos + Integer.SIZE / Byte.SIZE; break; case LONG: // Toggle highest order bit to return to original 2's complement. hbaseRowKey[pos] = (byte) ((int) hbaseRowKey[pos] ^ (int) Byte.MIN_VALUE); try { buf = ByteBuffer.wrap(hbaseRowKey, pos, Long.SIZE / Byte.SIZE); } catch (IndexOutOfBoundsException e) { throw new EntityIdException("Malformed hbase Row Key"); } fijiRowKey.add(Long.valueOf(buf.getLong())); pos = pos + Long.SIZE / Byte.SIZE; break; default: throw new RuntimeException("Invalid code path"); } fijiRowElem += 1; } // Fail if there are extra bytes in hbase row key. if (pos < hbaseRowKey.length) { throw new EntityIdException("Extra bytes in hbase row key cannot be mapped to any " + "component"); } // Fail if we encounter nulls before it is legal to do so. if (fijiRowElem < format.getNullableStartIndex()) { throw new EntityIdException("Too few components decoded from hbase row key. Component " + "number " + fijiRowElem + " cannot be null"); } // finish up with nulls for everything that wasn't in the key for (; fijiRowElem < format.getComponents().size(); fijiRowElem++) { fijiRowKey.add(null); } return fijiRowKey; }
From source file:it.unimi.dsi.sux4j.mph.TwoStepsLcpMonotoneMinimalPerfectHashFunction.java
/** * Creates a new two-steps LCP monotone minimal perfect hash function for the given keys. * /* w ww .java 2 s .co m*/ * @param keys the keys to hash. * @param numKeys the number of keys, or -1 if the number of keys is not known (will be computed). * @param transform a transformation strategy for the keys. * @param signatureWidth a signature width, or 0 for no signature. * @param tempDir a temporary directory for the store files, or {@code null} for the standard temporary directory. */ @SuppressWarnings("unused") protected TwoStepsLcpMonotoneMinimalPerfectHashFunction(final Iterable<? extends T> keys, final long numKeys, final TransformationStrategy<? super T> transform, final int signatureWidth, final File tempDir) throws IOException { final ProgressLogger pl = new ProgressLogger(LOGGER); pl.displayLocalSpeed = true; pl.displayFreeMemory = true; this.transform = transform; final RandomGenerator r = new XorShift1024StarRandomGenerator(); if (numKeys == -1) { if (keys instanceof Size64) n = ((Size64) keys).size64(); else if (keys instanceof Collection) n = ((Collection<?>) keys).size(); else { long c = 0; for (T dummy : keys) c++; n = c; } } else n = numKeys; defRetValue = -1; // For the very few cases in which we can decide if (n == 0) { seed = bucketSize = bucketSizeMask = log2BucketSize = 0; lcp2Bucket = null; offsets = null; lcpLengths = null; signatureMask = 0; signatures = null; return; } int t = (int) Math.ceil(1 + GOV3Function.C * Math.log(2) + Math.log(n) - Math.log(1 + Math.log(n))); log2BucketSize = Fast.ceilLog2(t); bucketSize = 1 << log2BucketSize; bucketSizeMask = bucketSize - 1; LOGGER.debug("Bucket size: " + bucketSize); final long numBuckets = (n + bucketSize - 1) / bucketSize; LongArrayBitVector prev = LongArrayBitVector.getInstance(); LongArrayBitVector curr = LongArrayBitVector.getInstance(); int currLcp = 0; @SuppressWarnings("resource") final OfflineIterable<BitVector, LongArrayBitVector> lcps = new OfflineIterable<BitVector, LongArrayBitVector>( BitVectors.OFFLINE_SERIALIZER, LongArrayBitVector.getInstance()); final int[][] lcpLengths = IntBigArrays.newBigArray((n + bucketSize - 1) / bucketSize); int maxLcp = 0; long maxLength = 0; @SuppressWarnings("resource") final ChunkedHashStore<BitVector> chunkedHashStore = new ChunkedHashStore<BitVector>( TransformationStrategies.identity(), pl); chunkedHashStore.reset(r.nextLong()); pl.expectedUpdates = n; pl.start("Scanning collection..."); Iterator<? extends T> iterator = keys.iterator(); for (long b = 0; b < numBuckets; b++) { prev.replace(transform.toBitVector(iterator.next())); chunkedHashStore.add(prev); pl.lightUpdate(); maxLength = Math.max(maxLength, prev.length()); currLcp = (int) prev.length(); final int currBucketSize = (int) Math.min(bucketSize, n - b * bucketSize); for (int i = 0; i < currBucketSize - 1; i++) { curr.replace(transform.toBitVector(iterator.next())); chunkedHashStore.add(curr); pl.lightUpdate(); final int prefix = (int) curr.longestCommonPrefixLength(prev); if (prefix == prev.length() && prefix == curr.length()) throw new IllegalArgumentException("The input bit vectors are not distinct"); if (prefix == prev.length() || prefix == curr.length()) throw new IllegalArgumentException("The input bit vectors are not prefix-free"); if (prev.getBoolean(prefix)) throw new IllegalArgumentException("The input bit vectors are not lexicographically sorted"); currLcp = Math.min(prefix, currLcp); prev.replace(curr); maxLength = Math.max(maxLength, prev.length()); } lcps.add(prev.subVector(0, currLcp)); IntBigArrays.set(lcpLengths, b, currLcp); maxLcp = Math.max(maxLcp, currLcp); } pl.done(); // We must be sure that both functions are built on the same store. chunkedHashStore.checkAndRetry(TransformationStrategies.wrap(keys, transform)); this.seed = chunkedHashStore.seed(); if (ASSERTS) { ObjectOpenHashSet<BitVector> s = new ObjectOpenHashSet<BitVector>(); for (LongArrayBitVector bv : lcps) s.add(bv.copy()); assert s.size() == lcps.size() : s.size() + " != " + lcps.size(); // No duplicates. } // Build function assigning each lcp to its bucket. lcp2Bucket = new GOV3Function.Builder<BitVector>().keys(lcps).transform(TransformationStrategies.identity()) .build(); if (DEBUG) { int p = 0; for (BitVector v : lcps) System.err.println(v + " " + v.length()); for (BitVector v : lcps) { final long value = lcp2Bucket.getLong(v); if (p++ != value) { System.err.println("p: " + (p - 1) + " value: " + value + " key:" + v); throw new AssertionError(); } } } lcps.close(); // Build function assigning the bucket offset to each element. offsets = new GOV3Function.Builder<BitVector>().store(chunkedHashStore).values(new AbstractLongBigList() { public long getLong(long index) { return index & bucketSizeMask; } public long size64() { return n; } }, log2BucketSize).indirect().build(); // Build function assigning the lcp length to each element. this.lcpLengths = new TwoStepsGOV3Function.Builder<BitVector>().store(chunkedHashStore) .values(new AbstractLongBigList() { public long getLong(long index) { return IntBigArrays.get(lcpLengths, index >>> log2BucketSize); } public long size64() { return n; } }).build(); // Build function assigning the lcp length and the bucketing data to each element. final double p = 1.0 / (this.lcpLengths.rankMean + 1); final double s = s(p, this.lcpLengths.width); LOGGER.debug("Forecast best threshold: " + s); if (DEBUG) { int j = 0; for (T key : keys) { BitVector bv = transform.toBitVector(key); if (j++ != lcp2Bucket.getLong(bv.subVector(0, this.lcpLengths.getLong(bv))) * bucketSize + offsets.getLong(bv)) { System.err.println("p: " + (j - 1) + " Key: " + key + " bucket size: " + bucketSize + " lcp " + transform.toBitVector(key).subVector(0, this.lcpLengths.getLong(bv)) + " lcp length: " + this.lcpLengths.getLong(bv) + " bucket " + lcp2Bucket .getLong(transform.toBitVector(key).subVector(0, this.lcpLengths.getLong(bv))) + " offset: " + offsets.getLong(bv)); throw new AssertionError(); } } } double secondFunctionForecastBitsPerElement = (s + GOV3Function.C + (Math.pow(2, s) - 1) * this.lcpLengths.width / n + (this.lcpLengths.width + GOV3Function.C) * (Math.pow(1 - p, Math.pow(2, s) + 1))); LOGGER.debug("Forecast bit cost per element: " + (log2BucketSize + GOV3Function.C + secondFunctionForecastBitsPerElement + (Fast.log2(Math.E)))); LOGGER.info("Actual bit cost per element: " + (double) numBits() / n); if (signatureWidth != 0) { signatureMask = -1L >>> Long.SIZE - signatureWidth; chunkedHashStore.filter(null); // two-steps functions use filtering. signatures = chunkedHashStore.signatures(signatureWidth, pl); } else { signatureMask = 0; signatures = null; } chunkedHashStore.close(); }
From source file:it.unimi.dsi.sux4j.mph.TwoStepsGOV3Function.java
/** Returns the number of bits used by this structure. * //from ww w . j av a 2 s . c o m * @return the number of bits used by this structure. */ public long numBits() { return (firstFunction != null ? firstFunction.numBits() : 0) + secondFunction.numBits() + transform.numBits() + remap.length * (long) Long.SIZE; }
From source file:it.unimi.dsi.sux4j.mph.MinimalPerfectHashFunction.java
/** * Creates a new minimal perfect hash function for the given keys. * // w w w. j a v a2 s .c om * @param keys the keys to hash, or {@code null}. * @param transform a transformation strategy for the keys. * @param signatureWidth a signature width, or 0 for no signature. * @param tempDir a temporary directory for the store files, or {@code null} for the standard temporary directory. * @param chunkedHashStore a chunked hash store containing the keys, or {@code null}; the store * can be unchecked, but in this case <code>keys</code> and <code>transform</code> must be non-{@code null}. */ protected MinimalPerfectHashFunction(final Iterable<? extends T> keys, final TransformationStrategy<? super T> transform, final int signatureWidth, final File tempDir, ChunkedHashStore<T> chunkedHashStore) throws IOException { this.transform = transform; final ProgressLogger pl = new ProgressLogger(LOGGER); pl.displayLocalSpeed = true; pl.displayFreeMemory = true; final RandomGenerator r = new XorShift1024StarRandomGenerator(); pl.itemsName = "keys"; final boolean givenChunkedHashStore = chunkedHashStore != null; if (!givenChunkedHashStore) { chunkedHashStore = new ChunkedHashStore<T>(transform, tempDir, pl); chunkedHashStore.reset(r.nextLong()); chunkedHashStore.addAll(keys.iterator()); } n = chunkedHashStore.size(); defRetValue = -1; // For the very few cases in which we can decide int log2NumChunks = Math.max(0, Fast.mostSignificantBit(n >> LOG2_CHUNK_SIZE)); chunkShift = chunkedHashStore.log2Chunks(log2NumChunks); final int numChunks = 1 << log2NumChunks; LOGGER.debug("Number of chunks: " + numChunks); seed = new long[numChunks]; offset = new long[numChunks + 1]; bitVector = LongArrayBitVector.getInstance(); (values = bitVector.asLongBigList(2)).size(((long) Math.ceil(n * HypergraphSorter.GAMMA) + 4 * numChunks)); array = bitVector.bits(); int duplicates = 0; for (;;) { LOGGER.debug("Generating minimal perfect hash function..."); long seed = 0; pl.expectedUpdates = numChunks; pl.itemsName = "chunks"; pl.start("Analysing chunks... "); try { int q = 0; for (ChunkedHashStore.Chunk chunk : chunkedHashStore) { final HypergraphSorter<BitVector> sorter = new HypergraphSorter<BitVector>(chunk.size(), false); do { seed = r.nextLong(); } while (!sorter.generateAndSort(chunk.iterator(), seed)); this.seed[q] = seed; offset[q + 1] = offset[q] + sorter.numVertices; /* We assign values. */ int top = chunk.size(), k, v = 0; final int[] stack = sorter.stack; final int[] vertex1 = sorter.vertex1; final int[] vertex2 = sorter.vertex2; final long off = offset[q]; while (top > 0) { v = stack[--top]; k = (v > vertex1[v] ? 1 : 0) + (v > vertex2[v] ? 1 : 0); assert k >= 0 && k < 3 : Integer.toString(k); //System.err.println( "<" + v + ", " + vertex1[v] + ", " + vertex2[ v ]+ "> (" + k + ")" ); final long s = values.getLong(off + vertex1[v]) + values.getLong(off + vertex2[v]); final long value = (k - s + 9) % 3; assert values.getLong(off + v) == 0; values.set(off + v, value == 0 ? 3 : value); } q++; pl.update(); if (ASSERTS) { final IntOpenHashSet pos = new IntOpenHashSet(); final int[] e = new int[3]; for (long[] triple : chunk) { HypergraphSorter.tripleToEdge(triple, seed, sorter.numVertices, sorter.partSize, e); assert pos.add(e[(int) (values.getLong(off + e[0]) + values.getLong(off + e[1]) + values.getLong(off + e[2])) % 3]); } } } pl.done(); break; } catch (ChunkedHashStore.DuplicateException e) { if (keys == null) throw new IllegalStateException( "You provided no keys, but the chunked hash store was not checked"); if (duplicates++ > 3) throw new IllegalArgumentException("The input list contains duplicates"); LOGGER.warn("Found duplicate. Recomputing triples..."); chunkedHashStore.reset(r.nextLong()); chunkedHashStore.addAll(keys.iterator()); } } globalSeed = chunkedHashStore.seed(); if (n > 0) { long m = values.size64(); final long length = bitVector.length(); final int numWords = (int) ((length + Long.SIZE - 1) / Long.SIZE); final int numCounts = (int) ((length + 32 * Long.SIZE - 1) / (32 * Long.SIZE)) * 2; // Init rank/select structure count = new long[numCounts + 1]; long c = 0; int pos = 0; for (int i = 0; i < numWords; i += WORDS_PER_SUPERBLOCK, pos += 2) { count[pos] = c; for (int j = 0; j < WORDS_PER_SUPERBLOCK; j++) { if (j != 0 && j % 6 == 0) count[pos + 1] |= (i + j <= numWords ? c - count[pos] : 0x7FFL) << 12 * (j / 6 - 1); if (i + j < numWords) c += countNonzeroPairs(array[i + j]); } } count[numCounts] = c; if (ASSERTS) { int k = 0; for (long i = 0; i < m; i++) { assert rank(i) == k : "(" + i + ") " + k + " != " + rank(i); if (values.getLong(i) != 0) k++; assert k <= n; } if (keys != null) { final Iterator<? extends T> iterator = keys.iterator(); for (long i = 0; i < n; i++) assert getLong(iterator.next()) < n; } } } else count = LongArrays.EMPTY_ARRAY; LOGGER.info("Completed."); LOGGER.debug( "Forecast bit cost per key: " + (2 * HypergraphSorter.GAMMA + 2. * Long.SIZE / BITS_PER_BLOCK)); LOGGER.info("Actual bit cost per key: " + (double) numBits() / n); if (signatureWidth != 0) { signatureMask = -1L >>> Long.SIZE - signatureWidth; (signatures = LongArrayBitVector.getInstance().asLongBigList(signatureWidth)).size(n); pl.expectedUpdates = n; pl.itemsName = "signatures"; pl.start("Signing..."); for (ChunkedHashStore.Chunk chunk : chunkedHashStore) { Iterator<long[]> iterator = chunk.iterator(); for (int i = chunk.size(); i-- != 0;) { final long[] triple = iterator.next(); final int[] e = new int[3]; signatures.set(getLongByTripleNoCheck(triple, e), signatureMask & triple[0]); pl.lightUpdate(); } } pl.done(); } else { signatureMask = 0; signatures = null; } if (!givenChunkedHashStore) chunkedHashStore.close(); }
From source file:it.unimi.dsi.sux4j.mph.GOVMinimalPerfectHashFunction.java
/** * Creates a new minimal perfect hash function for the given keys. * /*w w w . j a va 2 s. c o m*/ * @param keys the keys to hash, or {@code null}. * @param transform a transformation strategy for the keys. * @param signatureWidth a signature width, or 0 for no signature. * @param tempDir a temporary directory for the store files, or {@code null} for the standard temporary directory. * @param chunkedHashStore a chunked hash store containing the keys, or {@code null}; the store * can be unchecked, but in this case <code>keys</code> and <code>transform</code> must be non-{@code null}. */ protected GOVMinimalPerfectHashFunction(final Iterable<? extends T> keys, final TransformationStrategy<? super T> transform, final int signatureWidth, final File tempDir, ChunkedHashStore<T> chunkedHashStore) throws IOException { this.transform = transform; final ProgressLogger pl = new ProgressLogger(LOGGER); pl.displayLocalSpeed = true; pl.displayFreeMemory = true; final RandomGenerator r = new XorShift1024StarRandomGenerator(); pl.itemsName = "keys"; final boolean givenChunkedHashStore = chunkedHashStore != null; if (!givenChunkedHashStore) { chunkedHashStore = new ChunkedHashStore<T>(transform, tempDir, pl); chunkedHashStore.reset(r.nextLong()); chunkedHashStore.addAll(keys.iterator()); } n = chunkedHashStore.size(); defRetValue = -1; // For the very few cases in which we can decide int log2NumChunks = Math.max(0, Fast.mostSignificantBit(n >> LOG2_CHUNK_SIZE)); chunkShift = chunkedHashStore.log2Chunks(log2NumChunks); final int numChunks = 1 << log2NumChunks; LOGGER.debug("Number of chunks: " + numChunks); edgeOffsetAndSeed = new long[numChunks + 1]; bitVector = LongArrayBitVector.getInstance(); (values = bitVector.asLongBigList(2)).size(n * C_TIMES_256 >> 8); array = bitVector.bits(); int duplicates = 0; for (;;) { LOGGER.debug("Generating minimal perfect hash function..."); pl.expectedUpdates = numChunks; pl.itemsName = "chunks"; pl.start("Analysing chunks... "); try { int q = 0; long unorientable = 0, unsolvable = 0; for (ChunkedHashStore.Chunk chunk : chunkedHashStore) { edgeOffsetAndSeed[q + 1] = edgeOffsetAndSeed[q] + chunk.size(); long seed = 0; final long off = vertexOffset(edgeOffsetAndSeed[q]); final Linear3SystemSolver<BitVector> solver = new Linear3SystemSolver<BitVector>( (int) (vertexOffset(edgeOffsetAndSeed[q + 1]) - off), chunk.size()); for (;;) { final boolean solved = solver.generateAndSolve(chunk, seed, null); unorientable += solver.unorientable; unsolvable += solver.unsolvable; if (solved) break; seed += SEED_STEP; if (seed == 0) throw new AssertionError("Exhausted local seeds"); } this.edgeOffsetAndSeed[q] |= seed; final long[] solution = solver.solution; for (int i = 0; i < solution.length; i++) values.set(i + off, solution[i]); q++; pl.update(); if (ASSERTS) { final IntOpenHashSet pos = new IntOpenHashSet(); final int[] e = new int[3]; for (long[] triple : chunk) { Linear3SystemSolver.tripleToEquation(triple, seed, (int) (vertexOffset(edgeOffsetAndSeed[q]) - off), e); assert pos .add(e[(int) (values.getLong(off + e[0]) + values.getLong(off + e[1]) + values.getLong(off + e[2])) % 3]) : "<" + e[0] + "," + e[1] + "," + e[2] + ">: " + e[(int) (values.getLong(off + e[0]) + values.getLong(off + e[1]) + values.getLong(off + e[2])) % 3]; } } } LOGGER.info("Unorientable graphs: " + unorientable + "/" + numChunks + " (" + Util.format(100.0 * unorientable / numChunks) + "%)"); LOGGER.info("Unsolvable systems: " + unsolvable + "/" + numChunks + " (" + Util.format(100.0 * unsolvable / numChunks) + "%)"); pl.done(); break; } catch (ChunkedHashStore.DuplicateException e) { if (keys == null) throw new IllegalStateException( "You provided no keys, but the chunked hash store was not checked"); if (duplicates++ > 3) throw new IllegalArgumentException("The input list contains duplicates"); LOGGER.warn("Found duplicate. Recomputing triples..."); chunkedHashStore.reset(r.nextLong()); chunkedHashStore.addAll(keys.iterator()); } } globalSeed = chunkedHashStore.seed(); LOGGER.info("Completed."); LOGGER.debug("Forecast bit cost per key: " + 2 * C + 64. / (1 << LOG2_CHUNK_SIZE)); LOGGER.info("Actual bit cost per key: " + (double) numBits() / n); if (signatureWidth != 0) { signatureMask = -1L >>> Long.SIZE - signatureWidth; (signatures = LongArrayBitVector.getInstance().asLongBigList(signatureWidth)).size(n); pl.expectedUpdates = n; pl.itemsName = "signatures"; pl.start("Signing..."); for (ChunkedHashStore.Chunk chunk : chunkedHashStore) { Iterator<long[]> iterator = chunk.iterator(); for (int i = chunk.size(); i-- != 0;) { final long[] triple = iterator.next(); final int[] e = new int[3]; signatures.set(getLongByTripleNoCheck(triple, e), signatureMask & triple[0]); pl.lightUpdate(); } } pl.done(); } else { signatureMask = 0; signatures = null; } if (!givenChunkedHashStore) chunkedHashStore.close(); }
From source file:it.unimi.dsi.sux4j.mph.GOVMinimalPerfectHashFunction.java
/** * Returns the number of bits used by this structure. * /*from w w w . java2s . com*/ * @return the number of bits used by this structure. */ public long numBits() { return values.size64() * 2 + edgeOffsetAndSeed.length * (long) Long.SIZE; }
From source file:it.unimi.dsi.sux4j.mph.GOVMinimalPerfectHashFunction.java
@SuppressWarnings("unchecked") public long getLong(final Object key) { if (n == 0)/*ww w . j av a2 s. c o m*/ return defRetValue; final int[] e = new int[3]; final long[] h = new long[3]; Hashes.spooky4(transform.toBitVector((T) key), globalSeed, h); final int chunk = chunkShift == Long.SIZE ? 0 : (int) (h[0] >>> chunkShift); final long edgeOffsetSeed = edgeOffsetAndSeed[chunk]; final long chunkOffset = vertexOffset(edgeOffsetSeed); Linear3SystemSolver.tripleToEquation(h, edgeOffsetSeed & ~OFFSET_MASK, (int) (vertexOffset(edgeOffsetAndSeed[chunk + 1]) - chunkOffset), e); if (e[0] == -1) return defRetValue; final long result = (edgeOffsetSeed & OFFSET_MASK) + countNonzeroPairs(chunkOffset, chunkOffset + e[(int) (values.getLong(e[0] + chunkOffset) + values.getLong(e[1] + chunkOffset) + values.getLong(e[2] + chunkOffset)) % 3], array); if (signatureMask != 0) return result >= n || ((signatures.getLong(result) ^ h[0]) & signatureMask) != 0 ? defRetValue : result; return result < n ? result : defRetValue; }
From source file:it.unimi.dsi.sux4j.mph.MinimalPerfectHashFunction.java
/** * Returns the number of bits used by this structure. * //from w w w . j a va 2 s . c o m * @return the number of bits used by this structure. */ public long numBits() { return values.size64() * 2 + count.length * Long.SIZE + offset.length * (long) Long.SIZE + seed.length * (long) Long.SIZE; }
From source file:it.unimi.dsi.sux4j.mph.MinimalPerfectHashFunction.java
@SuppressWarnings("unchecked") public long getLong(final Object key) { if (n == 0)/*from ww w . j ava2s .com*/ return defRetValue; final int[] e = new int[3]; final long[] h = new long[3]; Hashes.spooky4(transform.toBitVector((T) key), globalSeed, h); final int chunk = chunkShift == Long.SIZE ? 0 : (int) (h[0] >>> chunkShift); final long chunkOffset = offset[chunk]; HypergraphSorter.tripleToEdge(h, seed[chunk], (int) (offset[chunk + 1] - chunkOffset), e); if (e[0] == -1) return defRetValue; final long result = rank(chunkOffset + e[(int) (values.getLong(e[0] + chunkOffset) + values.getLong(e[1] + chunkOffset) + values.getLong(e[2] + chunkOffset)) % 3]); if (signatureMask != 0) return result >= n || ((signatures.getLong(result) ^ h[0]) & signatureMask) != 0 ? defRetValue : result; // Out-of-set strings can generate bizarre 3-hyperedges. return result < n ? result : defRetValue; }
From source file:it.unimi.dsi.sux4j.mph.GOVMinimalPerfectHashFunction.java
/** Low-level access to the output of this minimal perfect hash function. * * <p>This method makes it possible to build several kind of functions on the same {@link ChunkedHashStore} and * then retrieve the resulting values by generating a single triple of hashes. The method * {@link TwoStepsGOV3Function#getLong(Object)} is a good example of this technique. * * @param triple a triple generated as documented in {@link ChunkedHashStore}. * @return the output of the function.//from w w w.j av a 2 s. c om */ public long getLongByTriple(final long[] triple) { if (n == 0) return defRetValue; final int[] e = new int[3]; final int chunk = chunkShift == Long.SIZE ? 0 : (int) (triple[0] >>> chunkShift); final long edgeOffsetSeed = edgeOffsetAndSeed[chunk]; final long chunkOffset = vertexOffset(edgeOffsetSeed); Linear3SystemSolver.tripleToEquation(triple, edgeOffsetSeed & ~OFFSET_MASK, (int) (vertexOffset(edgeOffsetAndSeed[chunk + 1]) - chunkOffset), e); if (e[0] == -1) return defRetValue; final long result = (edgeOffsetSeed & OFFSET_MASK) + countNonzeroPairs(chunkOffset, chunkOffset + e[(int) (values.getLong(e[0] + chunkOffset) + values.getLong(e[1] + chunkOffset) + values.getLong(e[2] + chunkOffset)) % 3], array); if (signatureMask != 0) return result >= n || signatures.getLong(result) != (triple[0] & signatureMask) ? defRetValue : result; return result < n ? result : defRetValue; }