return f;
}
public void test11() {
NativeMap nm = new NativeMap();
// insert things with varying field sizes and value sizes
// generate random data
Random r = new Random(75);
ArrayList<Pair<Key,Value>> testData = new ArrayList<Pair<Key,Value>>();
for (int i = 0; i < 100000; i++) {
Key k = new Key(rlrf(r, 97), rlrf(r, 13), rlrf(r, 31), rlrf(r, 11), (r.nextLong() & 0x7fffffffffffffffl), false, false);
Value v = new Value(rlrf(r, 511));
testData.add(new Pair<Key,Value>(k, v));
}
// insert unsorted data
for (Pair<Key,Value> pair : testData) {
nm.put(pair.getFirst(), pair.getSecond());
}
for (int i = 0; i < 2; i++) {
// sort data
Collections.sort(testData, new Comparator<Pair<Key,Value>>() {
@Override
public int compare(Pair<Key,Value> o1, Pair<Key,Value> o2) {
return o1.getFirst().compareTo(o2.getFirst());
}
});
// verify
Iterator<Entry<Key,Value>> iter1 = nm.iterator();
Iterator<Pair<Key,Value>> iter2 = testData.iterator();
while (iter1.hasNext() && iter2.hasNext()) {
Entry<Key,Value> e = iter1.next();
Pair<Key,Value> p = iter2.next();
if (!e.getKey().equals(p.getFirst()))
throw new RuntimeException("Keys not equal");
if (!e.getValue().equals(p.getSecond()))
throw new RuntimeException("Values not equal");
}
if (iter1.hasNext())
throw new RuntimeException("Not all of native map consumed");
if (iter2.hasNext())
throw new RuntimeException("Not all of test data consumed");
System.out.println("test 11 nm mem " + nm.getMemoryUsed());
// insert data again w/ different value
Collections.shuffle(testData, r);
// insert unsorted data
for (Pair<Key,Value> pair : testData) {
pair.getSecond().set(rlrf(r, 511));
nm.put(pair.getFirst(), pair.getSecond());
}
}
nm.delete();
}