Beispiel #1
0
 public int hashCode() {
   int hashcode = 0;
   byte[] states = this._states;
   for (int i = this._values.length; i-- > 0; ) {
     if (states[i] == 1) {
       hashcode += (HashFunctions.hash(this._set[i]) ^ HashFunctions.hash(this._values[i]));
     }
   }
   return hashcode;
 }
 /** {@inheritDoc} */
 @Override
 public int hashCode() {
   int hashcode = 0;
   byte[] states = _states;
   for (int i = _values.length; i-- > 0; ) {
     if (states[i] == FULL) {
       hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]);
     }
   }
   return hashcode;
 }
 /** {@inheritDoc} */
 @Override
 public int hashCode() {
   int hashcode = 0;
   TByteOffheapArray states = _states;
   for (int i = capacity(); i-- > 0; ) {
     if (states.get(i) == FULL) {
       hashcode += HashFunctions.hash(_set.get(i)) ^ HashFunctions.hash(_values.get(i));
     }
   }
   return hashcode;
 }
Beispiel #4
0
 /** {@inheritDoc} */
 @Override
 public int hashCode() {
   int h = 0;
   for (int i = _pos; i-- > 0; ) {
     h += HashFunctions.hash(_data[i]);
   }
   return h;
 }
 /** {@inheritDoc} */
 @Override
 public int hashCode() {
   int h = 0;
   for (int i = size(); i-- > 0; ) {
     h += HashFunctions.hash(get(i));
   }
   return h;
 }
Beispiel #6
0
  /**
   * Locates the index at which <tt>val</tt> can be inserted. if there is already a value equal()ing
   * <tt>val</tt> in the set, returns that value as a negative integer.
   *
   * @param val an <code>char</code> value
   * @return an <code>int</code> value
   */
  protected int insertionIndex(char val) {
    int hash, probe, index, length;

    final byte[] states = _states;
    final char[] set = _set;
    length = states.length;
    hash = HashFunctions.hash(val) & 0x7fffffff;
    index = hash % length;

    if (states[index] == FREE) {
      return index; // empty, all done
    } else if (states[index] == FULL && set[index] == val) {
      return -index - 1; // already stored
    } else { // already FULL or REMOVED, must probe
      // compute the double hash
      probe = 1 + (hash % (length - 2));

      // if the slot we landed on is FULL (but not removed), probe
      // until we find an empty slot, a REMOVED slot, or an element
      // equal to the one we are trying to insert.
      // finding an empty slot means that the value is not present
      // and that we should use that slot as the insertion point;
      // finding a REMOVED slot means that we need to keep searching,
      // however we want to remember the offset of that REMOVED slot
      // so we can reuse it in case a "new" insertion (i.e. not an update)
      // is possible.
      // finding a matching value means that we've found that our desired
      // key is already in the table

      if (states[index] != REMOVED) {
        // starting at the natural offset, probe until we find an
        // offset that isn't full.
        do {
          index -= probe;
          if (index < 0) {
            index += length;
          }
        } while (states[index] == FULL && set[index] != val);
      }

      // if the index we found was removed: continue probing until we
      // locate a free location or an element which equal()s the
      // one we have.
      if (states[index] == REMOVED) {
        int firstRemoved = index;
        while (states[index] != FREE && (states[index] == REMOVED || set[index] != val)) {
          index -= probe;
          if (index < 0) {
            index += length;
          }
        }
        return states[index] == FULL ? -index - 1 : firstRemoved;
      }
      // if it's full, the key is already stored
      return states[index] == FULL ? -index - 1 : index;
    }
  }
 /** {@inheritDoc} */
 public int hashCode() {
   int hashcode = 0;
   for (int i = _states.length; i-- > 0; ) {
     if (_states[i] == FULL) {
       hashcode += HashFunctions.hash(_set[i]);
     }
   }
   return hashcode;
 }
Beispiel #8
0
 public int hashCode() {
   int hashcode = 0;
   for (int i = TCharShortHashMap.this._states.length; i-- > 0; ) {
     if (TCharShortHashMap.this._states[i] == 1) {
       hashcode += HashFunctions.hash(TCharShortHashMap.this._set[i]);
     }
   }
   return hashcode;
 }
 @Override
 public int hashCode() {
   int hashcode = 0;
   for (int i = capacity(); i-- > 0; ) {
     if (_states.get(i) == FULL) {
       hashcode += HashFunctions.hash(_set.get(i));
     }
   }
   return hashcode;
 }
  /**
   * Locates the index of <tt>val</tt>.
   *
   * @param key an <code>byte</code> value
   * @return the index of <tt>val</tt> or -1 if it isn't in the set.
   */
  protected int index(byte key) {
    int hash, index, length;

    final byte[] states = _states;
    final byte[] set = _set;
    length = states.length;
    hash = HashFunctions.hash(key) & 0x7fffffff;
    index = hash % length;
    byte state = states[index];

    if (state == FREE) return -1;

    if (state == FULL && set[index] == key) return index;

    return indexRehashed(key, index, hash, state);
  }
Beispiel #11
0
  /**
   * Locates the index of <tt>val</tt>.
   *
   * @param val an <code>char</code> value
   * @return the index of <tt>val</tt> or -1 if it isn't in the set.
   */
  protected int index(char val) {
    int hash, probe, index, length;

    final byte[] states = _states;
    final char[] set = _set;
    length = states.length;
    hash = HashFunctions.hash(val) & 0x7fffffff;
    index = hash % length;

    if (states[index] != FREE && (states[index] == REMOVED || set[index] != val)) {
      // see Knuth, p. 529
      probe = 1 + (hash % (length - 2));

      do {
        index -= probe;
        if (index < 0) {
          index += length;
        }
      } while (states[index] != FREE && (states[index] == REMOVED || set[index] != val));
    }

    return states[index] == FREE ? -1 : index;
  }
  /**
   * Locates the index at which <tt>val</tt> can be inserted. if there is already a value equal()ing
   * <tt>val</tt> in the set, returns that value as a negative integer.
   *
   * @param key an <code>byte</code> value
   * @return an <code>int</code> value
   */
  protected int insertKey(byte val) {
    int hash, index;

    hash = HashFunctions.hash(val) & 0x7fffffff;
    index = hash % _states.length;
    byte state = _states[index];

    consumeFreeSlot = false;

    if (state == FREE) {
      consumeFreeSlot = true;
      insertKeyAt(index, val);

      return index; // empty, all done
    }

    if (state == FULL && _set[index] == val) {
      return -index - 1; // already stored
    }

    // already FULL or REMOVED, must probe
    return insertKeyRehash(val, index, hash, state);
  }