Ejemplo n.º 1
0
 public static bool IsMatch <TValue>(this IntPrefixTree <TValue> .Node root, PrefixKey ip) where TValue : class
 {
     for (int i = 0; i < root.Range; i++)
     {
         if (root.Key.IsSetAt(i) != ip.IsSetAt(i))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 2
0
        private Node GetRange(PrefixKey key, int range, out TValue lastMatch, out int depth)
        {
            Node cursor = _root;

            depth = 0;
            PrefixKey xor   = key ^ cursor.Key;
            var       match = true;

            lastMatch = null;
            while (depth < range && match)
            {
                if (depth < cursor.Range)
                {
                    if (match = !xor.IsSetAt(depth))
                    {
                        depth++;
                    }
                }
                else
                {
                    // remember the last match
                    lastMatch = cursor.Data ?? lastMatch;
                    // advance to the next nod
                    var nextIndex = key.ChildIndex(depth);
                    var next      = cursor[nextIndex];
                    if (next != null)
                    {
                        cursor = next;
                        // Contract.Assert(cursor.Range > depth);
                        xor = key ^ cursor.Key;
                        depth++;
                    }
                    else
                    {
                        match = false;
                    }
                }
            }
            // Contract.Assert(this.Depth0IffRoot(cursor, depth));
            // Contract.Assert(this.OnlyEndDigitIsDifferentIfNotRoot(cursor, key, range, depth));
            if (depth == cursor.Range)
            {
                lastMatch = cursor.Data ?? lastMatch;
            }
            return(cursor);
        }
Ejemplo n.º 3
0
 public static int ChildIndex(this PrefixKey value, int position)
 {
     return(value.IsSetAt(position) ? 1 : 0);
 }