public void Populate1() { KukuTable ct = new KukuTable( new KukuTableParameters { TableSize = 1, StashSize = 0, LocFuncCount = 2, LocFuncSeed = Item.MakeZeroItem(), MaxProbe = 10, EmptyItem = Item.MakeZeroItem() } ); Assert.IsTrue(ct.IsEmptyItem(ct[0])); Assert.IsTrue(ct.Insert(Item.MakeItem(1, 0))); Assert.IsFalse(ct.Insert(Item.MakeItem(0, 1))); Utilities.AssertThrows <ArgumentException>(() => ct.Insert(ct.EmptyItem)); Utilities.AssertThrows <ArgumentException>(() => ct.Insert(Item.MakeZeroItem())); Assert.IsFalse(ct.IsEmpty(0)); }
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}"); } } }