Example usage for org.apache.mahout.common RandomUtils MAX_INT_SMALLER_TWIN_PRIME

List of usage examples for org.apache.mahout.common RandomUtils MAX_INT_SMALLER_TWIN_PRIME

Introduction

In this page you can find the example usage for org.apache.mahout.common RandomUtils MAX_INT_SMALLER_TWIN_PRIME.

Prototype

int MAX_INT_SMALLER_TWIN_PRIME

To view the source code for org.apache.mahout.common RandomUtils MAX_INT_SMALLER_TWIN_PRIME.

Click Source Link

Document

The largest prime less than 231-1 that is the smaller of a twin prime pair.

Usage

From source file:im.xuwang.extmahout.cf.taste.impl.common.FastIDSet.java

License:Apache License

public FastIDSet(int size, float loadFactor) {
    Preconditions.checkArgument(size >= 0, "size must be at least 0");
    Preconditions.checkArgument(loadFactor >= 1.0f, "loadFactor must be at least 1.0");
    this.loadFactor = loadFactor;
    int max = (int) (RandomUtils.MAX_INT_SMALLER_TWIN_PRIME / loadFactor);
    Preconditions.checkArgument(size < max, "size must be less than %d", max);
    int hashSize = RandomUtils.nextTwinPrime((int) (loadFactor * size));
    keys = new long[hashSize]; // TODO: delete this line
    keysPositive = new long[hashSize];
    keysNegative = new long[hashSize];
    Arrays.fill(keys, NULL);//from   w  ww  . j av a2 s .c  om
}

From source file:im.xuwang.extmahout.cf.taste.impl.common.FastIDSet.java

License:Apache License

private void growAndRehash() {
    if (keys.length * loadFactor >= RandomUtils.MAX_INT_SMALLER_TWIN_PRIME) {
        throw new IllegalStateException("Can't grow any more");
    }/*from   w w w .  j  a v  a 2 s  . c o  m*/
    rehash(RandomUtils.nextTwinPrime((int) (loadFactor * keys.length)));
}

From source file:org.codelibs.elasticsearch.taste.common.FastByIDMap.java

License:Apache License

/**
 * Creates a new {@link FastByIDMap} whose capacity can accommodate the given number of entries without rehash.
 *
 * @param size desired capacity/*from  w  w  w .  j  a v a 2s . c o m*/
 * @param maxSize max capacity
 * @param loadFactor ratio of internal hash table size to current size
 * @throws IllegalArgumentException if size is less than 0, maxSize is less than 1
 *  or at least half of {@link RandomUtils#MAX_INT_SMALLER_TWIN_PRIME}, or
 *  loadFactor is less than 1
 */
public FastByIDMap(final int size, final int maxSize, final float loadFactor) {
    Preconditions.checkArgument(size >= 0, "size must be at least 0");
    Preconditions.checkArgument(loadFactor >= 1.0f, "loadFactor must be at least 1.0");
    this.loadFactor = loadFactor;
    final int max = (int) (RandomUtils.MAX_INT_SMALLER_TWIN_PRIME / loadFactor);
    Preconditions.checkArgument(size < max, "size must be less than " + max);
    Preconditions.checkArgument(maxSize >= 1, "maxSize must be at least 1");
    final int hashSize = RandomUtils.nextTwinPrime((int) (loadFactor * size));
    keys = new long[hashSize];
    Arrays.fill(keys, NULL);
    values = (V[]) new Object[hashSize];
    this.maxSize = maxSize;
    this.countingAccesses = maxSize != Integer.MAX_VALUE;
    this.recentlyAccessed = countingAccesses ? new BitSet(hashSize) : null;
}

From source file:org.codelibs.elasticsearch.taste.common.FastIDSet.java

License:Apache License

public FastIDSet(final int size, final float loadFactor) {
    Preconditions.checkArgument(size >= 0, "size must be at least 0");
    Preconditions.checkArgument(loadFactor >= 1.0f, "loadFactor must be at least 1.0");
    this.loadFactor = loadFactor;
    final int max = (int) (RandomUtils.MAX_INT_SMALLER_TWIN_PRIME / loadFactor);
    Preconditions.checkArgument(size < max, "size must be less than %d", max);
    final int hashSize = RandomUtils.nextTwinPrime((int) (loadFactor * size));
    keys = new long[hashSize];
    Arrays.fill(keys, NULL);/*  w ww . j ava  2  s  .c  o  m*/
}

From source file:org.codelibs.elasticsearch.taste.common.FastMap.java

License:Apache License

/**
 * Creates a new  whose capacity can accommodate the given number of entries without rehash.
 *
 * @param size desired capacity//from   w ww .  j  av a2  s  .c  o  m
 * @param maxSize max capacity
 * @throws IllegalArgumentException if size is less than 0, maxSize is less than 1
 *  or at least half of {@link RandomUtils#MAX_INT_SMALLER_TWIN_PRIME}, or
 *  loadFactor is less than 1
 */
public FastMap(final int size, final int maxSize, final float loadFactor) {
    Preconditions.checkArgument(size >= 0, "size must be at least 0");
    Preconditions.checkArgument(loadFactor >= 1.0f, "loadFactor must be at least 1.0");
    this.loadFactor = loadFactor;
    final int max = (int) (RandomUtils.MAX_INT_SMALLER_TWIN_PRIME / loadFactor);
    Preconditions.checkArgument(size < max, "size must be less than " + max);
    Preconditions.checkArgument(maxSize >= 1, "maxSize must be at least 1");
    final int hashSize = RandomUtils.nextTwinPrime((int) (loadFactor * size));
    keys = (K[]) new Object[hashSize];
    values = (V[]) new Object[hashSize];
    this.maxSize = maxSize;
    this.countingAccesses = maxSize != Integer.MAX_VALUE;
    this.recentlyAccessed = countingAccesses ? new BitSet(hashSize) : null;
}

From source file:org.gpfvic.mahout.cf.taste.impl.common.FastByIDMap.java

License:Apache License

/**
 * Creates a new {@link FastByIDMap} whose capacity can accommodate the given number of entries without rehash.
 * //  w w w .j  ava  2 s.c o  m
 * @param size desired capacity
 * @param maxSize max capacity
 * @param loadFactor ratio of internal hash table size to current size
 * @throws IllegalArgumentException if size is less than 0, maxSize is less than 1
 *  or at least half of {@link RandomUtils#MAX_INT_SMALLER_TWIN_PRIME}, or
 *  loadFactor is less than 1
 */
public FastByIDMap(int size, int maxSize, float loadFactor) {
    Preconditions.checkArgument(size >= 0, "size must be at least 0");
    Preconditions.checkArgument(loadFactor >= 1.0f, "loadFactor must be at least 1.0");
    this.loadFactor = loadFactor;
    int max = (int) (RandomUtils.MAX_INT_SMALLER_TWIN_PRIME / loadFactor);
    Preconditions.checkArgument(size < max, "size must be less than " + max);
    Preconditions.checkArgument(maxSize >= 1, "maxSize must be at least 1");
    int hashSize = RandomUtils.nextTwinPrime((int) (loadFactor * size));
    keys = new long[hashSize];
    Arrays.fill(keys, NULL);
    values = (V[]) new Object[hashSize];
    this.maxSize = maxSize;
    this.countingAccesses = maxSize != Integer.MAX_VALUE;
    this.recentlyAccessed = countingAccesses ? new BitSet(hashSize) : null;
}

From source file:org.gpfvic.mahout.cf.taste.impl.common.FastIDSet.java

License:Apache License

public FastIDSet(int size, float loadFactor) {
    Preconditions.checkArgument(size >= 0, "size must be at least 0");
    Preconditions.checkArgument(loadFactor >= 1.0f, "loadFactor must be at least 1.0");
    this.loadFactor = loadFactor;
    int max = (int) (RandomUtils.MAX_INT_SMALLER_TWIN_PRIME / loadFactor);
    Preconditions.checkArgument(size < max, "size must be less than %d", max);
    int hashSize = RandomUtils.nextTwinPrime((int) (loadFactor * size));
    keys = new long[hashSize];
    Arrays.fill(keys, NULL);//from   w w  w  .j a v  a  2  s  .c o  m
}

From source file:org.gpfvic.mahout.cf.taste.impl.common.FastMap.java

License:Apache License

/**
 * Creates a new  whose capacity can accommodate the given number of entries without rehash.
 * /*from   w  ww. j  a va 2 s.c o m*/
 * @param size desired capacity
 * @param maxSize max capacity
 * @throws IllegalArgumentException if size is less than 0, maxSize is less than 1
 *  or at least half of {@link RandomUtils#MAX_INT_SMALLER_TWIN_PRIME}, or
 *  loadFactor is less than 1
 */
public FastMap(int size, int maxSize, float loadFactor) {
    Preconditions.checkArgument(size >= 0, "size must be at least 0");
    Preconditions.checkArgument(loadFactor >= 1.0f, "loadFactor must be at least 1.0");
    this.loadFactor = loadFactor;
    int max = (int) (RandomUtils.MAX_INT_SMALLER_TWIN_PRIME / loadFactor);
    Preconditions.checkArgument(size < max, "size must be less than " + max);
    Preconditions.checkArgument(maxSize >= 1, "maxSize must be at least 1");
    int hashSize = RandomUtils.nextTwinPrime((int) (loadFactor * size));
    keys = (K[]) new Object[hashSize];
    values = (V[]) new Object[hashSize];
    this.maxSize = maxSize;
    this.countingAccesses = maxSize != Integer.MAX_VALUE;
    this.recentlyAccessed = countingAccesses ? new BitSet(hashSize) : null;
}