Example usage for org.apache.mahout.math.map HashFunctions hash

List of usage examples for org.apache.mahout.math.map HashFunctions hash

Introduction

In this page you can find the example usage for org.apache.mahout.math.map HashFunctions hash.

Prototype

public static int hash(boolean value) 

Source Link

Document

Returns a hashcode for the specified value.

Usage

From source file:gov.vha.isaac.cradle.collections.NativeIntIntHashMap.java

protected int indexOfInsertion(int key, int[] newTable, byte[] newState) {
    final int length = newTable.length;

    final int hash = HashFunctions.hash(key) & 0x7FFFFFFF;
    int i = hash % length;
    int decrement = hash % (length - 2); // double hashing, see http://www.eece.unm.edu/faculty/heileman/hash/node4.html
    //int decrement = (hash / length) % length;
    if (decrement == 0) {
        decrement = 1;//w  w  w.  jav a2 s .c  om
    }

    // stop if we find a removed or free slot, or if we find the key itself
    // do NOT skip over removed slots (yes, open addressing is like that...)
    while (newState[i] == FULL && newTable[i] != key) {
        i -= decrement;
        //hashCollisions++;
        if (i < 0) {
            i += length;
        }
    }

    if (newState[i] == REMOVED) {
        // stop if we find a free slot, or if we find the key itself.
        // do skip over removed slots (yes, open addressing is like that...)
        // assertion: there is at least one FREE slot.
        final int j = i;
        while (newState[i] != FREE && (newState[i] == REMOVED || newTable[i] != key)) {
            i -= decrement;
            //hashCollisions++;
            if (i < 0) {
                i += length;
            }
        }
        if (newState[i] == FREE) {
            i = j;
        }
    }

    if (newState[i] == FULL) {
        // key already contained at slot i.
        // return a negative number identifying the slot.
        return -i - 1;
    }
    // not already contained, should be inserted at slot i.
    // return a number >= 0 identifying the slot.
    return i;
}

From source file:gov.vha.isaac.ochre.collections.uuidnidmap.UuidToIntHashMap.java

License:Apache License

/**
 * @param key the key to be added to the receiver.
 * @return the index where the key would need to be inserted, if it is not already contained. Returns
 * -index-1 if the key is already contained at slot index. Therefore, if the returned index < 0, then it
 * is already contained at slot -index-1. If the returned index >= 0, then it is NOT already contained and
 * should be inserted at slot index.//from  w  ww  . j  av a  2  s  .  c  o  m
 */
protected int indexOfInsertion(long[] key) {
    final long tab[] = table;
    final byte stat[] = state;
    final int length = state.length;

    final int hash = HashFunctions.hash(key[0] + key[1]) & 0x7FFFFFFF;
    int i = hash % length;
    int decrement = hash % (length - 2); // double hashing, see
    // http://www.eece.unm.edu/faculty/heileman/hash/node4.html
    // int decrement = (hash / length) % length;
    if (decrement == 0) {
        decrement = 1;
    }

    // stop if we find a removed or free slot, or if we find the key itself
    // do NOT skip over removed slots (yes, open addressing is like that...)
    while (stat[i] == FULL && (tab[i * 2] != key[0] || tab[i * 2 + 1] != key[1])) {
        i -= decrement;
        // hashCollisions++;
        if (i < 0) {
            i += length;
        }
    }

    if (stat[i] == REMOVED) {
        // stop if we find a free slot, or if we find the key itself.
        // do skip over removed slots (yes, open addressing is like that...)
        // assertion: there is at least one FREE slot.
        int j = i;
        while (stat[i] != FREE && (stat[i] == REMOVED || (tab[i * 2] != key[0] || tab[i * 2 + 1] != key[1]))) {
            i -= decrement;
            // hashCollisions++;
            if (i < 0) {
                i += length;
            }
        }
        if (stat[i] == FREE) {
            i = j;
        }
    }

    if (stat[i] == FULL) {
        // key already contained at slot i.
        // return a negative number identifying the slot.
        return -i - 1;
    }
    // not already contained, should be inserted at slot i.
    // return a number >= 0 identifying the slot.
    return i;
}

From source file:gov.vha.isaac.ochre.collections.uuidnidmap.UuidToIntHashMap.java

License:Apache License

/**
 * @param key the key to be searched in the receiver.
 * @return the index where the key is contained in the receiver, returns -1 if the key was not found.
 *///from   ww  w  .j  av a 2s . c o m
protected int indexOfKey(long[] key) {
    final long tab[] = table;
    final byte stat[] = state;
    final int length = stat.length;

    final int hash = HashFunctions.hash(key[0] + key[1]) & 0x7FFFFFFF;
    int i = hash % length;
    int decrement = hash % (length - 2); // double hashing, see
    // http://www.eece.unm.edu/faculty/heileman/hash/node4.html
    // int decrement = (hash / length) % length;
    if (decrement == 0) {
        decrement = 1;
    }

    // stop if we find a free slot, or if we find the key itself.
    // do skip over removed slots (yes, open addressing is like that...)
    while (stat[i] != FREE && (stat[i] == REMOVED || (tab[i * 2] != key[0] || tab[i * 2 + 1] != key[1]))) {
        i -= decrement;
        // hashCollisions++;
        if (i < 0) {
            i += length;
        }
    }

    if (stat[i] == FREE) {
        return -1; // not found
    }
    return i; // found, return index where key is contained
}

From source file:gov.vha.isaac.ochre.collections.uuidnidmap.UuidToIntHashMap.java

License:Apache License

protected int indexOfInsertionForRehash(long[] key, long[] tab, byte[] stat) {
    final int length = stat.length;

    final int hash = HashFunctions.hash(key[0] + key[1]) & 0x7FFFFFFF;
    int i = hash % length;
    int decrement = hash % (length - 2); // double hashing, see
    // http://www.eece.unm.edu/faculty/heileman/hash/node4.html
    // int decrement = (hash / length) % length;
    if (decrement == 0) {
        decrement = 1;/*from  www  . j  a v a 2 s  .c  om*/
    }

    // stop if we find a removed or free slot, or if we find the key itself
    // do NOT skip over removed slots (yes, open addressing is like that...)
    while (stat[i] == FULL && (tab[i * 2] != key[0] || tab[i * 2 + 1] != key[1])) {
        i -= decrement;
        // hashCollisions++;
        if (i < 0) {
            i += length;
        }
    }

    if (stat[i] == REMOVED) {
        // stop if we find a free slot, or if we find the key itself.
        // do skip over removed slots (yes, open addressing is like that...)
        // assertion: there is at least one FREE slot.
        int j = i;
        while (stat[i] != FREE && (stat[i] == REMOVED || (tab[i * 2] != key[0] || tab[i * 2 + 1] != key[1]))) {
            i -= decrement;
            // hashCollisions++;
            if (i < 0) {
                i += length;
            }
        }
        if (stat[i] == FREE) {
            i = j;
        }
    }

    if (stat[i] == FULL) {
        // key already contained at slot i.
        // return a negative number identifying the slot.
        return -i - 1;
    }
    // not already contained, should be inserted at slot i.
    // return a number >= 0 identifying the slot.
    return i;
}

From source file:org.ihtsdo.otf.tcc.datastore.uuidnidmap.UuidToIntHashMap.java

License:Apache License

protected int indexOfKey(UUID key) {
    final long tab[] = table;
    final byte stat[] = state;
    final int length = stat.length;

    final int hash = HashFunctions.hash(key.getMostSignificantBits() + key.getLeastSignificantBits())
            & 0x7FFFFFFF;//from   www  .  j a v a 2  s  . c  o  m
    int i = hash % length;
    int decrement = hash % (length - 2); // double hashing, see
    // http://www.eece.unm.edu/faculty/heileman/hash/node4.html
    // int decrement = (hash / length) % length;
    if (decrement == 0) {
        decrement = 1;
    }

    // stop if we find a free slot, or if we find the key itself.
    // do skip over removed slots (yes, open addressing is like that...)
    while (stat[i] != FREE && (stat[i] == REMOVED || (tab[i * 2] != key.getMostSignificantBits()
            || tab[i * 2 + 1] != key.getLeastSignificantBits()))) {
        i -= decrement;
        // hashCollisions++;
        if (i < 0) {
            i += length;
        }
    }

    if (stat[i] == FREE) {
        return -1; // not found
    }
    return i; // found, return index where key is contained
}

From source file:sh.isaac.api.collections.NativeIntIntHashMap.java

License:Apache License

/**
 * Index of insertion./*from   w  w  w .j av a 2 s  .co m*/
 *
 * @param key the key
 * @param newTable the new table
 * @param newState the new state
 * @return the int
 */
protected int indexOfInsertion(int key, int[] newTable, byte[] newState) {
    final int length = newTable.length;
    final int hash = HashFunctions.hash(key) & 0x7FFFFFFF;
    int i = hash % length;
    int decrement = hash % (length - 2); // double hashing, see http://www.eece.unm.edu/faculty/heileman/hash/node4.html

    // int decrement = (hash / length) % length;
    if (decrement == 0) {
        decrement = 1;
    }

    // stop if we find a removed or free slot, or if we find the key itself
    // do NOT skip over removed slots (yes, open addressing is like that...)
    while ((newState[i] == FULL) && (newTable[i] != key)) {
        i -= decrement;

        // hashCollisions++;
        if (i < 0) {
            i += length;
        }
    }

    if (newState[i] == REMOVED) {
        // stop if we find a free slot, or if we find the key itself.
        // do skip over removed slots (yes, open addressing is like that...)
        // assertion: there is at least one FREE slot.
        final int j = i;

        while ((newState[i] != FREE) && ((newState[i] == REMOVED) || (newTable[i] != key))) {
            i -= decrement;

            // hashCollisions++;
            if (i < 0) {
                i += length;
            }
        }

        if (newState[i] == FREE) {
            i = j;
        }
    }

    if (newState[i] == FULL) {
        // key already contained at slot i.
        // return a negative number identifying the slot.
        return -i - 1;
    }

    // not already contained, should be inserted at slot i.
    // return a number >= 0 identifying the slot.
    return i;
}

From source file:sh.isaac.api.collections.uuidnidmap.UuidToIntHashMap.java

License:Apache License

/**
 * Index of insertion.//from www .j a v  a2 s .  c  o  m
 *
 * @param key the key to be added to the receiver.
 * @return the index where the key would need to be inserted, if it is not already contained. Returns
 * -index-1 if the key is already contained at slot index. Therefore, if the returned index < 0, then it
 * is already contained at slot -index-1. If the returned index >= 0, then it is NOT already contained and
 * should be inserted at slot index.
 */
protected int indexOfInsertion(long[] key) {
    final long tab[] = this.table;
    final byte stat[] = this.state;
    final int length = this.state.length;
    final int hash = HashFunctions.hash(key[0] + key[1]) & 0x7FFFFFFF;
    int i = hash % length;
    int decrement = hash % (length - 2); // double hashing, see

    // http://www.eece.unm.edu/faculty/heileman/hash/node4.html
    // int decrement = (hash / length) % length;
    if (decrement == 0) {
        decrement = 1;
    }

    // stop if we find a removed or free slot, or if we find the key itself
    // do NOT skip over removed slots (yes, open addressing is like that...)
    while ((stat[i] == FULL) && ((tab[i * 2] != key[0]) || (tab[i * 2 + 1] != key[1]))) {
        i -= decrement;

        // hashCollisions++;
        if (i < 0) {
            i += length;
        }
    }

    if (stat[i] == REMOVED) {
        // stop if we find a free slot, or if we find the key itself.
        // do skip over removed slots (yes, open addressing is like that...)
        // assertion: there is at least one FREE slot.
        final int j = i;

        while ((stat[i] != FREE)
                && ((stat[i] == REMOVED) || ((tab[i * 2] != key[0]) || (tab[i * 2 + 1] != key[1])))) {
            i -= decrement;

            // hashCollisions++;
            if (i < 0) {
                i += length;
            }
        }

        if (stat[i] == FREE) {
            i = j;
        }
    }

    if (stat[i] == FULL) {
        // key already contained at slot i.
        // return a negative number identifying the slot.
        return -i - 1;
    }

    // not already contained, should be inserted at slot i.
    // return a number >= 0 identifying the slot.
    return i;
}

From source file:sh.isaac.api.collections.uuidnidmap.UuidToIntHashMap.java

License:Apache License

/**
 * Index of insertion for rehash./*from  w  w w  .  j  av  a 2  s  .  c  om*/
 *
 * @param key the key
 * @param tab the tab
 * @param stat the stat
 * @return the int
 */
protected int indexOfInsertionForRehash(long[] key, long[] tab, byte[] stat) {
    final int length = stat.length;
    final int hash = HashFunctions.hash(key[0] + key[1]) & 0x7FFFFFFF;
    int i = hash % length;
    int decrement = hash % (length - 2); // double hashing, see

    // http://www.eece.unm.edu/faculty/heileman/hash/node4.html
    // int decrement = (hash / length) % length;
    if (decrement == 0) {
        decrement = 1;
    }

    // stop if we find a removed or free slot, or if we find the key itself
    // do NOT skip over removed slots (yes, open addressing is like that...)
    while ((stat[i] == FULL) && ((tab[i * 2] != key[0]) || (tab[i * 2 + 1] != key[1]))) {
        i -= decrement;

        // hashCollisions++;
        if (i < 0) {
            i += length;
        }
    }

    if (stat[i] == REMOVED) {
        // stop if we find a free slot, or if we find the key itself.
        // do skip over removed slots (yes, open addressing is like that...)
        // assertion: there is at least one FREE slot.
        final int j = i;

        while ((stat[i] != FREE)
                && ((stat[i] == REMOVED) || ((tab[i * 2] != key[0]) || (tab[i * 2 + 1] != key[1])))) {
            i -= decrement;

            // hashCollisions++;
            if (i < 0) {
                i += length;
            }
        }

        if (stat[i] == FREE) {
            i = j;
        }
    }

    if (stat[i] == FULL) {
        // key already contained at slot i.
        // return a negative number identifying the slot.
        return -i - 1;
    }

    // not already contained, should be inserted at slot i.
    // return a number >= 0 identifying the slot.
    return i;
}

From source file:sh.isaac.api.collections.uuidnidmap.UuidToIntHashMap.java

License:Apache License

/**
 * Index of key.//from ww  w. j a  v  a  2  s .c  o  m
 *
 * @param key the key to be searched in the receiver.
 * @return the index where the key is contained in the receiver, returns -1 if the key was not found.
 */
protected int indexOfKey(long[] key) {
    final long tab[] = this.table;
    final byte stat[] = this.state;
    final int length = stat.length;
    final int hash = HashFunctions.hash(key[0] + key[1]) & 0x7FFFFFFF;
    int i = hash % length;
    int decrement = hash % (length - 2); // double hashing, see

    // http://www.eece.unm.edu/faculty/heileman/hash/node4.html
    // int decrement = (hash / length) % length;
    if (decrement == 0) {
        decrement = 1;
    }

    // stop if we find a free slot, or if we find the key itself.
    // do skip over removed slots (yes, open addressing is like that...)
    while ((stat[i] != FREE)
            && ((stat[i] == REMOVED) || ((tab[i * 2] != key[0]) || (tab[i * 2 + 1] != key[1])))) {
        i -= decrement;

        // hashCollisions++;
        if (i < 0) {
            i += length;
        }
    }

    if (stat[i] == FREE) {
        return -1; // not found
    }

    return i; // found, return index where key is contained
}

From source file:sh.isaac.api.memory.MemoryManagedReference.java

License:Apache License

/**
 * Hash code.
 *
 * @return the int
 */
@Override
public int hashCode() {
    return HashFunctions.hash(this.objectId);
}