/// <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); }
/// <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(); } }
/// <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()); }
/// <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; }