public void TestMemoryReuse() { int maxId = 4096; int[] maxNumItems = { 1, 1, 2, 2, 3, 3, 3, 3, 1, 1 }; int[] minNumItems = { 1, 1, 0, 1, 0, 0, 2, 3, 1, 0 }; int[] count = new int[maxId]; BigInt32Buffer buffer = new BigInt32Buffer(); BigNestedInt32Array.BufferedLoader loader = null; BigNestedInt32Array nestedArray = new BigNestedInt32Array(); Random rand = new Random(); for (int i = 0; i < maxNumItems.Length; i++) { loader = new BigNestedInt32Array.BufferedLoader(maxId, BigNestedInt32Array.MAX_ITEMS, buffer); for (int id = 0; id < maxId; id++) { count[id] = 0; int cnt = Math.Max(rand.Next(maxNumItems[i] + 1), minNumItems[i]); for (int val = 0; val < cnt; val++) { if (loader.Add(id, val)) { count[id]++; } } } nestedArray.Load(maxId, loader); int[] buf = new int[1024]; for (int id = 0; id < maxId; id++) { int cnt = nestedArray.GetData(id, buf); Assert.AreEqual(count[id], cnt, "count[" + i + "," + id + "]"); if (cnt > 0) { for (int val = 0; val < cnt; val++) { Assert.AreEqual(val, buf[val], "item[" + i + "," + id + "," + val + "]"); } } } if (i == 0) { maxId = maxId * 2; count = new int[maxId]; } } }
public void TestCountNoReturnWithFilter() { int maxId = 20; int numVals = 10; int[] count = new int[numVals]; var loader = new BigNestedInt32Array.BufferedLoader(maxId); for (int val = 0; val < numVals; val++) { for (int i = 0; i < maxId - val; i++) { loader.Add(i, val); } } BigNestedInt32Array nestedArray = new BigNestedInt32Array(); nestedArray.Load(maxId, loader); OpenBitSet filter = new OpenBitSet(numVals); for (int i = 0; i < numVals; i++) { if (i % 2 == 0) { filter.Set(i); } } for (int i = 0; i < maxId; i++) { nestedArray.CountNoReturnWithFilter(i, count, filter); } for (int i = 0; i < numVals; i++) { if (i % 2 == 0) { Assert.True(count[i] == maxId - i); } else { Assert.True(count[i] == 0); } } return; }
public void TestBufferedLoaderReuse() { int maxId = 5000; int[] maxNumItems = { 25, 50, 20, 100, 15, 500, 10, 1000, 5, 2000, 2 }; int[,] count = new int[maxNumItems.Length, maxId]; var buffer = new BigInt32Buffer(); var loader = new BigNestedInt32Array.BufferedLoader(maxId, BigNestedInt32Array.MAX_ITEMS, buffer); var nestedArray = new BigNestedInt32Array[maxNumItems.Length]; for (int i = 0; i < maxNumItems.Length; i++) { for (int id = 0; id < maxId; id++) { int cnt = id % (maxNumItems[i] + 1); for (int val = 0; val < cnt; val++) { if (loader.Add(id, val)) { count[i, id]++; } } } nestedArray[i] = new BigNestedInt32Array(); nestedArray[i].Load(maxId, loader); loader.Reset(maxId, BigNestedInt32Array.MAX_ITEMS, buffer); } for (int i = 0; i < maxNumItems.Length; i++) { int[] buf = new int[1024]; for (int id = 0; id < maxId; id++) { int cnt = nestedArray[i].GetData(id, buf); Assert.AreEqual(count[i, id], cnt, "count[" + i + "," + id + "]"); if (cnt > 0) { for (int val = 0; val < cnt; val++) { Assert.AreEqual(val, buf[val], "item[" + i + "," + id + "," + val + "]"); } } } } }
public void TestSparseIds() { int maxId = 100000; int[] count = new int[maxId]; var loader = new BigNestedInt32Array.BufferedLoader(maxId); for (int id = 0; id < maxId; id += ((id >> 2) + 1)) { for (int val = 0; val < 3000; val += (id + 1)) { if (loader.Add(id, val)) { count[id]++; } } } var nestedArray = new BigNestedInt32Array(); nestedArray.Load(maxId, loader); int[] buf = new int[1024]; for (int id = 0; id < maxId; id++) { int cnt = nestedArray.GetData(id, buf); Assert.AreEqual(count[id], cnt, "item count"); if (cnt > 0) { int val = 0; for (int i = 0; i < cnt; i++) { Assert.AreEqual(val, buf[i], "item[" + i + "]"); val += (id + 1); } } } }