Example #1
0
 /// <summary>
 /// Find all of the keys.
 /// </summary>
 /// <param name="n"> </param>
 /// <param name="data"> </param>
 /// <param name="key"> </param>
 private bool KeyWalker(TrieNode n, object data, ByteStack key)
 {
     if (n.Value != null)
     {
         ArrayList al = (ArrayList) data;
         al.Add((byte[]) key);
     }
     return true;
 }
Example #2
0
            public bool MoveNext()
            {
                if (m_pos.Count <= 0)
                {
                    return false;
                }

                m_current = (TrieNode) m_pos.Pop();

                foreach (TrieNode e in m_current)
                {
                    m_pos.Push(e);
                }

                if (m_current.Value != null)
                {
                    return true;
                }

                return MoveNext();
            }
Example #3
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 #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>
 protected void Traverse(TrieWalker w, object data, TrieNode current)
 {
     if (! w(current, data))
     {
         return;
     }
     foreach (TrieNode e in current)
     {
         Traverse(w, data, e);
     }
 }
Example #5
0
 /// <summary>
 /// Deletes all nodes.
 /// </summary>
 public void Clear()
 {
     m_root  = new TrieNode(null, 0);
     m_count = 0;
 }
Example #6
0
        /// <summary>
        /// Finds a node in the given sub-tree.
        /// </summary>
        /// <param name="key">The key to search on, where key[0] corresponds to a child of startAt.</param>
        /// <param name="startAt">The node to search under</param>
        /// <param name="create">Create nodes that don't exist, while searching.</param>
        /// <returns>The node if found. If the node doesn't exist and create is true, the node created; otherwise null.</returns>
        protected virtual TrieNode FindNode(byte[] key, TrieNode startAt, bool create)
        {
            TrieNode current = startAt;
            byte b;

            for (int i=0; (i<key.Length) && (current != null); i++)
            {
                b = key[i];
                current = current[b, create];
            }
            return current;
        }
Example #7
0
 /// <summary>
 /// Traverse the trie, computing indexes.
 /// </summary>
 /// <param name="n"> </param>
 /// <param name="data"> </param>
 private bool IndexWalker(TrieNode n, object data)
 {
     if (n.Parent != null)
     {
          this[n.Byte].Add(new WeakReference(n));
     }
     return true;
 }
Example #8
0
 /// <summary>
 /// Copy the keys from the sub-tree into an ArrayList.
 /// </summary>
 /// <param name="n"> </param>
 /// <param name="data"> </param>
 /// <param name="key"> </param>
 private bool CopyWalker(TrieNode n, object data, ByteStack key)
 {
     if (n.Value != null)
     {
         ArrayList al = (ArrayList) data;
         al.Add((byte[]) key);
         if (al.Count >= m_maxResults)
         {
             return false;
         }
     }
     return true;
 }
Example #9
0
 /// <summary>
 /// Create a new node
 /// </summary>
 /// <param name="parent">The parent of the new node</param>
 /// <param name="key">The byte for this node</param>
 public TrieNode(TrieNode parent, byte key)
 {
     m_parent = parent;
     m_key    = key;
 }
Example #10
0
 public TrieNodeEnumerator(TrieNode n)
 {
     m_node = n;
     Reset();
 }
Example #11
0
 /// <summary>
 /// Adds a child to this node.
 /// </summary>
 /// <param name="key">The key for the child.</param>
 /// <returns>The child noded added to this node.</returns>
 private TrieNode Add(byte key)
 {
     TrieNode e = new TrieNode(this, key);
     this[key]  = e;
     return e;
 }