예제 #1
0
        public static bool OnlyEndDigitIsDifferentIfNotRoot <TValue>(this IntPrefixTree <TValue> tree, IntPrefixTree <TValue> .Node cursor, PrefixKey key, int range, int depth) where TValue : class
        {
            if (cursor == tree.Root)
            {
                return(true);
            }
            var xor = cursor.Key ^ key;

            for (int i = 0; i < depth && i < cursor.Range && i < range; i++)
            {
                if (xor.IsSetAt(i))
                {
                    return(false);
                }
            }
            if (cursor.Range == depth)
            {
                return(true);
            }
            if (range == depth)
            {
                return(true);
            }
            if (!xor.IsSetAt(depth))
            {
                return(false);
            }
            return(true);
        }
예제 #2
0
        public static bool Depth0IffRoot <TValue>(this IntPrefixTree <TValue> tree, IntPrefixTree <TValue> .Node cursor, int depth) where TValue : class
        {
            var isRoot   = cursor == tree.Root;
            var depthIs0 = depth == 0;

            return(depthIs0 == isRoot);
        }
예제 #3
0
        public static IntPrefixTree <TValue> .Node GetNode <TValue>(this IntPrefixTree <TValue> tree, params int[] path) where TValue : class
        {
            var cursor = tree.Root;

            foreach (var index in path)
            {
                cursor = cursor[index];
            }
            return(cursor);
        }
예제 #4
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);
 }
예제 #5
0
 public static bool FindKey <TValue>(this IntPrefixTree <TValue> .Node root, PrefixKey ip) where TValue : class
 {
     if (root.Key == ip)
     {
         return(true);
     }
     else
     {
         return((root[0] != null && root[0].FindKey(ip)) || (root[1] != null && root[1].FindKey(ip)));
     }
 }
예제 #6
0
 public static string Truncate <TValue>(this IntPrefixTree <TValue> .Node root, PrefixKey ip) where TValue : class
 {
     return(ip.ToBinary().Substring(0, root.Range));
 }