public static uint GetOrGetNext(this FixedSizeNode <SnapUInt32, SnapUInt32> tree, uint key) { SnapUInt32 k = new SnapUInt32(key); SnapUInt32 v = new SnapUInt32(); tree.GetOrGetNext(k, v); return(v.Value); }
public static uint GetFirstValue(this FixedSizeNode <SnapUInt32, SnapUInt32> tree) { SnapUInt32 k = new SnapUInt32(); SnapUInt32 v = new SnapUInt32(); tree.TryGetFirstRecord(k, v); return(v.Value); }
public static bool TryInsert(this FixedSizeNode <SnapUInt32, SnapUInt32> tree, uint key, uint value) { SnapUInt32 k = new SnapUInt32(key); SnapUInt32 v = new SnapUInt32(value); bool rv = tree.TryInsert(k, v); return(rv); }
public static void GetLastKeyValue(this FixedSizeNode <SnapUInt32, SnapUInt32> tree, out uint key, out uint value) { SnapUInt32 k = new SnapUInt32(); SnapUInt32 v = new SnapUInt32(); tree.TryGetLastRecord(k, v); key = k.Value; value = v.Value; }
public static bool TryGet(this FixedSizeNode <SnapUInt32, SnapUInt32> tree, uint key, out uint value) { SnapUInt32 k = new SnapUInt32(key); SnapUInt32 v = new SnapUInt32(); bool rv = tree.TryGet(k, v); value = v.Value; return(rv); }
public static void Insert(this FixedSizeNode <SnapUInt32, SnapUInt32> tree, uint key, uint value) { SnapUInt32 k = new SnapUInt32(key); SnapUInt32 v = new SnapUInt32(value); if (!tree.TryInsert(k, v)) { throw new Exception(); } }
public static uint Get(this FixedSizeNode <SnapUInt32, SnapUInt32> tree, uint key) { SnapUInt32 k = new SnapUInt32(key); SnapUInt32 v = new SnapUInt32(); if (!tree.TryGet(k, v)) { throw new Exception(); } return(v.Value); }
public void Test_CreateRootNode_Get() { uint rootKey = 0; byte rootLevel = 0; uint nextKeyIndex = 0; Func <uint> getNextKey = () => { nextKeyIndex++; return(nextKeyIndex - 1); }; Action <SnapUInt32, uint, byte> addToParent = (int32, u, arg3) => int32 = int32; Func <SnapUInt32, uint> findLeafNode = int32 => 0; Stopwatch swWrite = new Stopwatch(); Stopwatch swRead = new Stopwatch(); using (BinaryStream bs = new BinaryStream()) { uint k, v; FixedSizeNode <SnapUInt32, SnapUInt32> node = new FixedSizeNode <SnapUInt32, SnapUInt32>(0); node.Initialize(bs, 1024, getNextKey, null); node.CreateEmptyNode(0); node.Insert(1, 100); node.Insert(2, 200); Assert.AreEqual(0u, node.NodeIndex); Assert.AreEqual(uint.MaxValue, node.LeftSiblingNodeIndex); Assert.AreEqual(uint.MaxValue, node.RightSiblingNodeIndex); Assert.AreEqual(1u, node.GetFirstKey()); Assert.AreEqual(100u, node.GetFirstValue()); Assert.AreEqual(2u, node.GetLastKey()); Assert.AreEqual(200u, node.GetLastValue()); Assert.AreEqual(100u, node.Get(1)); Assert.AreEqual(200u, node.Get(2)); Assert.AreEqual(100u, node.GetOrGetNext(1)); Assert.AreEqual(200u, node.GetOrGetNext(2)); Assert.AreEqual(200u, node.GetOrGetNext(3)); node.SetNodeIndex(0); Assert.AreEqual(0u, node.NodeIndex); Assert.AreEqual(uint.MaxValue, node.LeftSiblingNodeIndex); Assert.AreEqual(uint.MaxValue, node.RightSiblingNodeIndex); Assert.AreEqual(1u, node.GetFirstKey()); Assert.AreEqual(100u, node.GetFirstValue()); Assert.AreEqual(2u, node.GetLastKey()); Assert.AreEqual(200u, node.GetLastValue()); Assert.AreEqual(100u, node.Get(1)); Assert.AreEqual(200u, node.Get(2)); Assert.AreEqual(100u, node.GetOrGetNext(1)); Assert.AreEqual(200u, node.GetOrGetNext(2)); Assert.AreEqual(200u, node.GetOrGetNext(3)); } }
public static uint LowerKey(this FixedSizeNode <SnapUInt32, SnapUInt32> tree) { return(tree.LowerKey.Value); }
public static bool KeyInsideBounds(this FixedSizeNode <SnapUInt32, SnapUInt32> tree, uint key) { SnapUInt32 k = new SnapUInt32(key); return(tree.IsKeyInsideBounds(k)); }