Example #1
0
        /// <summary>
        /// Return a list of keys that contain the given substring.
        /// </summary>
        /// <param name="lookFor">The substring to search for.</param>
        public ArrayList SubString(byte[] lookFor)
        {
            ArrayList starts = (ArrayList)m_indexes[lookFor[0]];
            ArrayList finds  = new ArrayList();

            byte[] nBuf = new byte[lookFor.Length - 1];
            Buffer.BlockCopy(lookFor, 1, nBuf, 0, lookFor.Length - 1);
            TrieKeyWalker w = new TrieKeyWalker(CopyWalker);

            foreach (WeakReference wref in starts)
            {
                if (finds.Count >= m_maxResults)
                {
                    break;
                }
                TrieNode first = (TrieNode)wref.Target;
                if (first == null)
                {
                    // node got removed out from underneath.
                    starts.Remove(wref);
                }
                else
                {
                    TrieNode last = FindNode(nBuf, first, false);
                    if (last != null)
                    {
                        Traverse(w, finds, last, new ByteStack(last.Key));
                    }
                }
            }
            return(finds);
        }
Example #2
0
 /// <summary>
 /// Perform the given function on every element of the trie.  Perl's map() operator.
 /// </summary>
 /// <param name="w">The function to call</param>
 /// <param name="data">Extra data to pass along to the function.</param>
 /// <param name="current">What node are we currently on?</param>
 /// <param name="key">A stack holding the current key value</param>
 protected void Traverse(TrieKeyWalker w, object data, TrieNode current, ByteStack key)
 {
     if (!w(current, data, key))
     {
         return;
     }
     foreach (TrieNode e in current)
     {
         key.Push(e.Byte);
         Traverse(w, data, e, key);
         key.Pop();
     }
 }
Example #3
0
 /// <summary>
 /// Performs the given function on every element of the trie. This is equivalent to Perl's map() operator.
 /// </summary>
 /// <param name="w">The function to call</param>
 /// <param name="data">Extra data to pass along to the function.</param>
 public void Traverse(TrieKeyWalker w, object data)
 {
     Traverse(w, data, m_root, new ByteStack());
 }
Example #4
0
 /// <summary>
 /// Perform the given function on every element of the trie.  Perl's map() operator.
 /// </summary>
 /// <param name="w">The function to call</param>
 /// <param name="data">Extra data to pass along to the function.</param>
 /// <param name="current">What node are we currently on?</param>
 /// <param name="key">A stack holding the current key value</param>
 protected void Traverse(TrieKeyWalker w, object data, TrieNode current, ByteStack key)
 {
     if (!w(current, data, key))
     {
         return;
     }
     foreach (TrieNode e in current)
     {
         key.Push(e.Byte);
         Traverse(w, data, e, key);
         key.Pop();
     }
 }
Example #5
0
 /// <summary>
 /// Performs the given function on every element of the trie. This is equivalent to Perl's map() operator.
 /// </summary>
 /// <param name="w">The function to call</param>
 /// <param name="data">Extra data to pass along to the function.</param>
 public void Traverse(TrieKeyWalker w, object data)
 {
     Traverse(w, data, m_root, new ByteStack());
 }
Example #6
0
 /// <summary>
 /// Return a list of keys that contain the given substring.
 /// </summary>
 /// <param name="lookFor">The substring to search for.</param>
 public ArrayList SubString(byte[] lookFor)
 {
     ArrayList starts = (ArrayList) m_indexes[lookFor[0]];
     ArrayList finds = new ArrayList();
     byte[] nBuf = new byte[lookFor.Length - 1];
     Buffer.BlockCopy(lookFor, 1, nBuf, 0, lookFor.Length - 1);
     TrieKeyWalker w = new TrieKeyWalker(CopyWalker);
     foreach (WeakReference wref in starts)
     {
         if (finds.Count >= m_maxResults)
         {
             break;
         }
         TrieNode first = (TrieNode) wref.Target;
         if (first == null)
         {
             // node got removed out from underneath.
             starts.Remove(wref);
         }
         else
         {
             TrieNode last = FindNode(nBuf, first, false);
             if (last != null)
             {
                 Traverse(w, finds, last, new ByteStack(last.Key));
             }
         }
     }
     return finds;
 }