コード例 #1
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;
 }
コード例 #2
0
ファイル: Trie.cs プロジェクト: newyorknight/jabber.net
        /// <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;
        }
コード例 #3
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;
 }
コード例 #4
0
 [Test] public void Test_Main()
 {
     System.Text.Encoding ENC = System.Text.Encoding.Default;
     TrieNode n = new TrieNode(null, 0);
     byte[] key = ENC.GetBytes("test");
     TrieNode current = n;
     for (int i=0; i<key.Length; i++)
     {
         byte b = key[i];
         current = current[b, true];
     }
     current.Value = "foo";
     Assert.AreEqual(ENC.GetString(key), ENC.GetString(current.Key));
 }
コード例 #5
0
ファイル: Trie.cs プロジェクト: newyorknight/jabber.net
            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();
            }
コード例 #6
0
ファイル: Trie.cs プロジェクト: newyorknight/jabber.net
 /// <summary>
 /// Deletes all nodes.
 /// </summary>
 public void Clear()
 {
     m_root  = new TrieNode(null, 0);
     m_count = 0;
 }
コード例 #7
0
ファイル: Trie.cs プロジェクト: newyorknight/jabber.net
 /// <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;
 }
コード例 #8
0
ファイル: Trie.cs プロジェクト: newyorknight/jabber.net
 /// <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);
     }
 }
コード例 #9
0
ファイル: Trie.cs プロジェクト: newyorknight/jabber.net
 /// <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();
     }
 }
コード例 #10
0
ファイル: TrieNode.cs プロジェクト: newyorknight/jabber.net
 /// <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>
 public virtual TrieNode Add(byte key)
 {
     TrieNode e = new TrieNode(this, key);
     this[key]  = e;
     return e;
 }
コード例 #11
0
ファイル: TrieNode.cs プロジェクト: newyorknight/jabber.net
 /// <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;
 }
コード例 #12
0
ファイル: TrieNode.cs プロジェクト: newyorknight/jabber.net
 public TrieNodeEnumerator(TrieNode n)
 {
     m_node = n;
     Reset();
 }