public Cache(int size, int members) { Test.check(members >= 1, "Cache members must be greater than 0"); Test.check(members <= 3, "Cache members must be less than 4"); cache_bits = (size < 32) ? 5 : Digits.closest_log2(size); // min size 32 cache_size = (1 << cache_bits); cache_mask = cache_size - 1; this.members = members; numgrows = 0; last_access = numaccess = 0; possible_bins_count = 0; numclears = numpartial_clears = 0; entries = new CacheEntry[cache_size]; for (int i = 0; i < cache_size; i++) { entries[i] = new CacheEntry(); } }
/** testbench. do not call */ public static void internal_test() { Test.start("SetEnumeration"); final BDDUniverse u = new BDDUniverse(dom); final Set set = u.createEmptySet(); final int[] val = new int[dom.length]; int real_size = 0; for (int i = 0; i < 200; i++) { for (int j = 0; j < dom.length; j++) { val[j] = (int) (Math.random() * dom[j]); } if (set.insert(val)) { real_size++; } } Test.checkEquality( real_size, set.cardinality(), "# of elemnets inserted equals set cardinality"); final Set set2 = set.copy(); final SetEnumeration se = set.elements(); int had = 0; while (se.hasMoreElements()) { had++; final int[] v = se.nextElement(); Test.check(set2.remove(v), " returned element really in set"); } Test.checkEquality( real_size, set.cardinality(), "# of elemnets inserted still equals set cardinality"); Test.checkEquality(had, set.cardinality(), "right number of elements in set"); Test.checkEquality(set2.cardinality(), 0, "right number of elements in set (Same as above)"); set2.free(); set.free(); se.free(); Test.end(); }
/** testbench. do not call */ public static void internal_test() { Test.start("Cache"); // 3 elements Cache cache = new Cache(200, 3); cache.insert3((byte) 2, 1, 2, 3); Test.check(cache.lookup3((byte) 2, 1, 2) == 3, "lookup 3"); cache.insert3((byte) 2, 1, 2, 5); Test.check(cache.lookup3((byte) 2, 1, 2) == 5, "lookup overwritten with 5"); Test.check(cache.lookup3((byte) 1, 1, 2) == -1, "non-existing entry 1"); Test.check(cache.lookup3((byte) 2, 2, 2) == -1, "non-existing entry 2"); Test.check(cache.lookup3((byte) 2, 2, 1) == -1, "non-existing entry 3"); // 2 elements cache = new Cache(200, 2); cache.insert2((byte) 2, 1, 3); Test.check(cache.lookup2((byte) 2, 1) == 3, "lookup 3"); cache.insert2((byte) 2, 1, 5); Test.check(cache.lookup2((byte) 2, 1) == 5, "lookup overwritten with 5"); Test.check(cache.lookup2((byte) 1, 1) == -1, "non-existing entry 1"); Test.check(cache.lookup2((byte) 2, 2) == -1, "non-existing entry 2"); // 1 element cache = new Cache(200, 1); cache.insert1(1, 3); Test.check(cache.lookup1(1) == 3, "lookup 3"); cache.insert1(1, 5); Test.check(cache.lookup1(1) == 5, "lookup overwritten with 5"); Test.check(cache.lookup1(2) == -1, "non-existing entry 1"); Test.check(cache.lookup1(3) == -1, "non-existing entry 2"); Test.end(); }