Search in sources :

Example 1 with HijackBag

use of jcog.bag.impl.HijackBag in project narchy by automenta.

the class BagTest method testPutMinMaxAndUniqueness.

public static void testPutMinMaxAndUniqueness(Bag<Integer, PriReference<Integer>> a) {
    float pri = 0.5f;
    // insert enough to fully cover all slots. strings have bad hashcode when input iteratively so this may need to be a high multiple
    int n = a.capacity() * 16;
    for (int i = 0; i < n; i++) {
        a.put(new PLink((i), pri));
    }
    // commit but dont forget
    a.commit(null);
    assertEquals(a.capacity(), a.size());
    if (a instanceof ArrayBag)
        assertSorted((ArrayBag) a);
    // a.print();
    // System.out.println(n + " " + a.size());
    List<Integer> keys = new FasterList(a.capacity());
    a.forEachKey(keys::add);
    assertEquals(a.size(), keys.size());
    assertEquals(new HashSet(keys).size(), keys.size());
    assertEquals(pri, a.priMin(), 0.01f);
    assertEquals(a.priMin(), a.priMax(), 0.08f);
    if (a instanceof HijackBag)
        assertTrue(((HijackBag) a).density() > 0.75f);
}
Also used : PLink(jcog.pri.PLink) DefaultHijackBag(jcog.bag.impl.hijack.DefaultHijackBag) HijackBag(jcog.bag.impl.HijackBag) ArrayBag(jcog.bag.impl.ArrayBag) FasterList(jcog.list.FasterList)

Aggregations

ArrayBag (jcog.bag.impl.ArrayBag)1 HijackBag (jcog.bag.impl.HijackBag)1 DefaultHijackBag (jcog.bag.impl.hijack.DefaultHijackBag)1 FasterList (jcog.list.FasterList)1 PLink (jcog.pri.PLink)1