/** Find the position in the table of a given handle using handles. * * <p>Note that this function compares handles. Thus, it always returns a correct value. * @param v a bit vector. * @param handleLength the length of the prefix of <code>v</code> that will be used as a handle. * @param s the signature of the prefix of <code>v</code> of <code>handleLength</code> bits. * * @return the position in the table where the specified handle can be found, or a position containing {@code null}. */ protected int findExactPos(final BitVector v, final long handleLength, final long s) { int pos = hash(s); while(node[pos] != null) { // Position is not empty if ((signature[pos] & SIGNATURE_MASK) == s && // Same signature handleLength == node[pos].handleLength() && // Same handle length v.equals(node[pos].reference.key(transform), 0, handleLength)) // Same handle return pos; pos = (pos + 1) & mask; } return -1; }
/** Find the position in the table of a given handle using signatures. * * <p>Note that this function just compares signatures (except for duplicates, which are * checked explicitly). Thus, it might return false positives when queried with * keys that are not handles. Nonetheless, it will always return a correct result on a handle. * * @param v a bit vector. * @param handleLength the length of the prefix of <code>v</code> that will be used as a handle. * @param s the signature of the prefix of <code>v</code> of <code>handleLength</code> bits. * * @return the position in the table where the specified handle can be found, or a position containing {@code null}. */ protected int findPos(final BitVector v, final long handleLength, final long s) { int pos = hash(s); while(signature[pos] != 0) { // Position is not empty if ((signature[pos] & SIGNATURE_MASK) == s // Same signature && ((signature[pos] & DUPLICATE_MASK) == 0 // It's not a duplicate || (handleLength == node[pos].handleLength() && // Same handle length (it's a duplicate) v.equals(node[pos].reference.key(transform), 0, handleLength)))) // Same handle return pos; pos = (pos + 1) & mask; } return -1; }