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 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 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 GetFirstValue(this FixedSizeNode<SnapUInt32, SnapUInt32> tree)
 {
     SnapUInt32 k = new SnapUInt32();
     SnapUInt32 v = new SnapUInt32();
     tree.TryGetFirstRecord(k, v);
     return v.Value;
 }
示例#5
0
 /// <summary>
 /// Creates a new sparse index. Be sure to initialize this class by calling <see cref="Initialize"/> before using this.
 /// </summary>
 public SparseIndex()
 {
     m_initializer = Library.CreateTreeNode <TKey, SnapUInt32>(EncodingDefinition.FixedSizeCombinedEncoding, 0);
     m_tmpKey      = new TKey();
     m_keySize     = m_tmpKey.Size;
     m_tmpValue    = new SnapUInt32();
 }
        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 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 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 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 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);
        }
示例#16
0
 /// <summary>
 /// Updates the value for the provided key.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 /// <param name="level"></param>
 public void UpdateValue(TKey key, SnapUInt32 value, byte level)
 {
     if (level <= RootNodeLevel)
     {
         GetNode(level).UpdateValue(key, value);
     }
     else
     {
         throw new Exception("Cannot update value of root");
     }
 }
示例#17
0
 /// <summary>
 /// Adds the following node pointer to the sparse index.
 /// </summary>
 /// <param name="nodeKey">the first key in the <see cref="pointer"/>. Only uses the key portion of the TKeyValue</param>
 /// <param name="pointer">the index of the later node</param>
 /// <param name="level">the level of the node being added</param>
 /// <remarks>This class will add the new node data to the parent node,
 /// or create a new root if the current root is split.</remarks>
 public void Add(TKey nodeKey, uint pointer, byte level)
 {
     if (level <= RootNodeLevel)
     {
         SnapUInt32 value = new SnapUInt32(pointer);
         GetNode(level).TryInsert(nodeKey, value);
     }
     else //A new root node needs to be created.
     {
         CreateNewRootNode(nodeKey, pointer);
     }
 }
示例#18
0
        public unsafe void TestRandom(int count)
        {
            int loopCount = 200;

            uint[] items      = new uint[count];
            uint[] lookupList = new uint[count];

            for (uint x = 0; x < items.Length; x++)
            {
                items[x]      = 2 * x;
                lookupList[x] = 2 * x + 1;
            }
            Shuffle(lookupList, 3, 10);

            StepTimer.Reset();
            for (int cnt = 0; cnt < loopCount; cnt++)
            {
                //GC.Collect(0);

                //items = (uint[])items.Clone();

                //GC.WaitForPendingFinalizers();
                //System.Threading.Thread.Sleep(10);

                SnapCustomMethodsUInt32 bin = new SnapCustomMethodsUInt32();
                fixed(uint *lp = items)
                {
                    byte *     lpp = (byte *)lp;
                    SnapUInt32 box = new SnapUInt32();

                    StepTimer.ITimer timer = StepTimer.Start("Lookup");
                    for (int x = 0; x < lookupList.Length; x++)
                    {
                        box.Value = lookupList[x];
                        bin.BinarySearch(lpp, box, count, 4);
                        //BoxKeyMethodsUint32.BinarySearchTest(lpp, box, count, 4);
                    }
                    timer.Stop();
                }
            }

            StringBuilder SB = new StringBuilder();

            //Console.Write(count.ToString("Tree\t0\t"));
            //SB.Append((count * 4).ToString("0\t") + (count / StepTimer.GetAverage("Lookup") / 1000000).ToString("0.000\t"));
            //SB.Append((count * 4.0 / 1024).ToString("0.###\t") + ((StepTimer.GetAverage("Lookup") / Math.Log(count, 2)) / count * 1000000000).ToString("0.00\t"));
            SB.Append(((StepTimer.GetSlowest("Lookup") / Math.Log(count, 2)) / count * 1000000000).ToString("0.00\t"));
            //SB.Append(((StepTimer.GetAverage("Lookup") / Math.Log(count, 2)) / count * 1000000000).ToString("0.00\t"));
            Console.WriteLine(SB.ToString());
        }
 protected override bool ReadNext(TKey key, SnapUInt32 value)
 {
     if (!m_isReading)
     {
         throw new Exception("Must call SwitchToReading() first.");
     }
     if (m_readingCount < m_count)
     {
         m_readingCount++;
         key.Read(m_stream);
         value.Read(m_stream);
         return(true);
     }
     return(false);
 }
 public static bool KeyInsideBounds(this FixedSizeNode<SnapUInt32, SnapUInt32> tree, uint key)
 {
     SnapUInt32 k = new SnapUInt32(key);
     return tree.IsKeyInsideBounds(k);
 }
        public static bool KeyInsideBounds(this FixedSizeNode <SnapUInt32, SnapUInt32> tree, uint key)
        {
            SnapUInt32 k = new SnapUInt32(key);

            return(tree.IsKeyInsideBounds(k));
        }