Search in sources :

Example 1 with MetalBitSet

use of jcog.data.bit.MetalBitSet in project narchy by automenta.

the class Simplify2D method douglasPeuckerSimplify.

// / <summary>
// / Ramer-Douglas-Peucker polygon simplification algorithm. This is the
// general recursive version that does not use the
// / speed-up technique by using the Melkman convex hull.
// /
// / If you pass in 0, it will remove all collinear points
// / </summary>
// / <returns>The simplified polygon</returns>
public static FasterList<v2> douglasPeuckerSimplify(FasterList<v2> vertices, float distanceTolerance) {
    // _distanceTolerance = distanceTolerance;
    int n = vertices.size();
    MetalBitSet usePt = MetalBitSet.bits(n);
    usePt.setAll();
    simplifySection(usePt, distanceTolerance, vertices, 0, n - 1);
    FasterList<v2> result = new FasterList<v2>();
    for (int i = 0; i < n; i++) if (usePt.get(i))
        result.add(vertices.get(i));
    return result;
}
Also used : FasterList(jcog.list.FasterList) MetalBitSet(jcog.data.bit.MetalBitSet)

Example 2 with MetalBitSet

use of jcog.data.bit.MetalBitSet in project narchy by automenta.

the class SimpleIntSet method index.

/**
 * Gets the index of the given key. Based on that {@link #status} variable,
 * the index is either the location to insert OR the location of the key.
 * <p>
 * This method returns 2 integer table in the long. The lower 32 bits are
 * the index that either contains the key, or is the first empty index.
 * <p>
 * The upper 32 bits is the index of the first position marked as
 * {@link #DELETED} either {@link Integer#MIN_VALUE} if no position was
 * marked as DELETED while searching.
 *
 * @param key they key to search for
 * @return the mixed long containing the index of the first DELETED position
 * and the position that the key is in or the first EMPTY position found
 */
private int index(int key) {
    // D1
    final int hash = key & 0x7fffffff;
    int[] k = this.keys;
    int len = k.length;
    int i = hash % len;
    // D2
    MetalBitSet s = this.status;
    if (!s.get(i) || k[i] == key)
        return i;
    // D3
    final int c = 1 + (hash % (len - 2));
    while (// this loop will terminate
    true) {
        // D4
        i -= c;
        if (i < 0)
            i += len;
        // D5
        if (!s.get(i) || k[i] == key)
            return i;
    }
}
Also used : MetalBitSet(jcog.data.bit.MetalBitSet)

Example 3 with MetalBitSet

use of jcog.data.bit.MetalBitSet in project narchy by automenta.

the class LongBitsetBloomFilter method add.

public final void add(byte[] val) {
    // We use the trick mentioned in "Less Hashing, Same Performance: Building a Better Bloom Filter"
    // by Kirsch et.al. From abstract 'only two hash functions are necessary to effectively
    // implement a Bloom filter without any loss in the asymptotic false positive probability'
    // Lets split up 64-bit hashcode into two 32-bit hashcodes and employ the technique mentioned
    // in the above paper
    long hash64 = Murmur3Hash.hash64(val);
    int hash1 = (int) hash64;
    int hash2 = (int) (hash64 >>> 32);
    int k = this.k;
    int m = this.m;
    MetalBitSet bits = bitSet;
    for (int i = 1; i <= k; i++) {
        int combinedHash = combineHash(hash1, hash2, i);
        bits.set(/*pos*/
        combinedHash % m);
    }
}
Also used : MetalBitSet(jcog.data.bit.MetalBitSet)

Example 4 with MetalBitSet

use of jcog.data.bit.MetalBitSet in project narchy by automenta.

the class LongBitsetBloomFilter method test.

public boolean test(byte[] val) {
    long hash64 = Murmur3Hash.hash64(val);
    int hash1 = (int) hash64;
    int hash2 = (int) (hash64 >>> 32);
    int k = this.k;
    int m = this.m;
    MetalBitSet bits = bitSet;
    for (int i = 1; i <= k; i++) {
        int combinedHash = combineHash(hash1, hash2, i);
        if (!bits.get(/*pos*/
        combinedHash % m)) {
            return false;
        }
    }
    return true;
}
Also used : MetalBitSet(jcog.data.bit.MetalBitSet)

Example 5 with MetalBitSet

use of jcog.data.bit.MetalBitSet in project narchy by automenta.

the class SimpleIntSet method enlargeIfNeeded.

private void enlargeIfNeeded() {
    if (size + 1 < keys.length * loadFactor)
        return;
    // enlarge
    final MetalBitSet oldSatus = status;
    final int[] oldKeys = keys;
    // it will actually end up doubling in size since we have twin primes spaced that was
    int newSize = getNextPow2TwinPrime(keys.length * 3 / 2);
    alloc(newSize);
    size = 0;
    for (int oldIndex = 0; oldIndex < oldKeys.length; oldIndex++) if (oldSatus.get(oldIndex))
        add(oldKeys[oldIndex]);
}
Also used : MetalBitSet(jcog.data.bit.MetalBitSet)

Aggregations

MetalBitSet (jcog.data.bit.MetalBitSet)5 FasterList (jcog.list.FasterList)1