public void Fill2() { KukuTable ct = new KukuTable( new KukuTableParameters { TableSize = (1 << 10) - 1, StashSize = 0, LocFuncCount = 4, LocFuncSeed = Item.MakeZeroItem(), MaxProbe = 100, EmptyItem = Item.MakeRandomItem() } ); List <Item> insertedItems = new List <Item>(); for (uint i = 0; i < 600; i++) { insertedItems.Add(Item.MakeRandomItem()); Assert.IsTrue(ct.Insert(insertedItems[insertedItems.Count - 1])); } foreach (Item it in insertedItems) { Assert.IsTrue(ct.Query(it).Found); } Assert.IsFalse(ct.Query(Item.MakeRandomItem()).Found); }
public void Fill3() { KukuTable ct = new KukuTable( new KukuTableParameters { TableSize = (1 << 10) + 1, StashSize = 4, LocFuncCount = 2, LocFuncSeed = Item.MakeZeroItem(), MaxProbe = 100, EmptyItem = Item.MakeRandomItem() } ); List <Item> insertedItems = new List <Item>(); for (uint i = 0; i < 950; i++) { insertedItems.Add(Item.MakeRandomItem()); if (!ct.Insert(insertedItems[insertedItems.Count - 1])) { Item it = insertedItems.Find((Item it) => it.Equals(ct.LeftoverItem)); Assert.IsNotNull(it); Assert.IsFalse(ct.Query(ct.LeftoverItem).Found); insertedItems.Remove(it); } } foreach (Item it in insertedItems) { Assert.IsTrue(ct.Query(it).Found); } Assert.IsFalse(ct.Query(Item.MakeRandomItem()).Found); }
public void Populate2() { KukuTable ct = new KukuTable( new KukuTableParameters { TableSize = 1 << 10, StashSize = 0, LocFuncCount = 2, LocFuncSeed = Item.MakeZeroItem(), MaxProbe = 10, EmptyItem = Item.MakeZeroItem() } ); for (uint i = 0; i < ct.TableSize; i++) { Assert.IsTrue(ct.IsEmpty(i)); } Assert.IsTrue(ct.Insert(Item.MakeItem(1, 0))); Assert.IsTrue(ct.Insert(Item.MakeItem(0, 1))); Assert.IsTrue(ct.Insert(Item.MakeItem(1, 1))); Assert.IsTrue(ct.Insert(Item.MakeItem(2, 2))); Utilities.AssertThrows <ArgumentException>(() => ct.Insert(ct.EmptyItem)); Utilities.AssertThrows <ArgumentException>(() => ct.Insert(Item.MakeZeroItem())); int nonEmpties = 0; for (uint i = 0; i < ct.TableSize; i++) { nonEmpties += ct.IsEmpty(i) ? 0 : 1; } Assert.AreEqual(4, nonEmpties); Assert.IsTrue(ct.Query(Item.MakeItem(1, 0)).Found); Assert.IsTrue(ct.Query(Item.MakeItem(0, 1)).Found); Assert.IsTrue(ct.Query(Item.MakeItem(1, 1)).Found); Assert.IsTrue(ct.Query(Item.MakeItem(2, 2)).Found); Assert.IsFalse(ct.Query(Item.MakeItem(3, 3)).Found); }
static void RunExample(KukuTableParameters parameters) { var kukuTable = new KukuTable(parameters); ulong roundCounter = 0; while (true) { Console.WriteLine($"Inserted {roundCounter * 20} items."); Console.WriteLine($"Fill rate: {kukuTable.FillRate}."); Console.ReadKey(); for (ulong i = 0; i < 20; i++) { var item = Item.MakeItem(i + 1, roundCounter + 1); if (!kukuTable.Insert(item)) { Console.WriteLine($"Insertion failed: round_counter = {roundCounter}, i = {i}"); Console.WriteLine($"Inserted successfully {roundCounter * 20 + i} items."); Console.WriteLine($"Fill rate: {kukuTable.FillRate}."); var lastItem = kukuTable.LeftoverItem; Console.WriteLine($"Leftover item: [{string.Join(',', lastItem)}]."); break; } } PrintTable(kukuTable); if (!kukuTable.IsEmptyItem(kukuTable.LeftoverItem)) { break; } roundCounter++; } while (true) { Console.WriteLine("Query item: "); var input = Console.ReadLine(); Item item; try { if (input == null) { continue; } var data = input.Split(",").Select(ulong.Parse).ToArray(); item = Item.MakeItem(data[0], data[1]); } catch { Console.WriteLine($"Incorrect format. Expected: <ulong>,<ulong>"); continue; } var result = kukuTable.Query(item); Console.WriteLine($"Found: {result.Found}"); if (result.Found) { Console.WriteLine($"Location: {result.Location}"); Console.WriteLine($"In stash: {result.InStash}"); Console.WriteLine($"Hash function index: {result.LocFuncIndex}"); } } }