private void ApplyHelper(byte[] buff, int buffsize, int maxbuffsize, TrieDelegate func, Object arg) { // If this node is a subscription, apply the function. if (m_refcnt > 0) { func(buff, buffsize, arg); } // Adjust the buffer. if (buffsize >= maxbuffsize) { maxbuffsize = buffsize + 256; buff = Utils.Realloc(buff, maxbuffsize); Debug.Assert(buff != null); } // If there are no subnodes in the trie, return. if (m_count == 0) { return; } // If there's one subnode (optimisation). if (m_count == 1) { buff[buffsize] = m_min; buffsize++; m_next[0].ApplyHelper(buff, buffsize, maxbuffsize, func, arg); return; } // If there are multiple subnodes. for (short c = 0; c != m_count; c++) { buff[buffsize] = (byte)(m_min + c); if (m_next[c] != null) { m_next[c].ApplyHelper(buff, buffsize + 1, maxbuffsize, func, arg); } } }
private void ApplyHelper(byte[] buffer, int bufferSize, int maxBufferSize, TrieDelegate func, object arg) { // If this node is a subscription, apply the function. if (m_referenceCount > 0) { func(buffer, bufferSize, arg); } // Adjust the buffer. if (bufferSize >= maxBufferSize) { maxBufferSize = bufferSize + 256; Array.Resize(ref buffer, maxBufferSize); Debug.Assert(buffer != null); } // If there are no subnodes in the trie, return. if (m_count == 0) { return; } // If there's one subnode (optimisation). if (m_count == 1) { buffer[bufferSize] = m_minCharacter; bufferSize++; m_next[0].ApplyHelper(buffer, bufferSize, maxBufferSize, func, arg); return; } // If there are multiple subnodes. for (short c = 0; c != m_count; c++) { buffer[bufferSize] = (byte)(m_minCharacter + c); if (m_next[c] != null) { m_next[c].ApplyHelper(buffer, bufferSize + 1, maxBufferSize, func, arg); } } }
// Apply the function supplied to each subscription in the trie. public void Apply([NotNull] TrieDelegate func, [CanBeNull] object arg) { ApplyHelper(null, 0, 0, func, arg); }
private void ApplyHelper(byte[] buff, int buffsize, int maxbuffsize, TrieDelegate func, Object arg) { // If this node is a subscription, apply the function. if (m_refcnt > 0) func(buff, buffsize, arg); // Adjust the buffer. if (buffsize >= maxbuffsize) { maxbuffsize = buffsize + 256; buff = Utils.Realloc(buff, maxbuffsize); Debug.Assert(buff != null); } // If there are no subnodes in the trie, return. if (m_count == 0) return; // If there's one subnode (optimisation). if (m_count == 1) { buff[buffsize] = m_min; buffsize++; m_next[0].ApplyHelper(buff, buffsize, maxbuffsize, func, arg); return; } // If there are multiple subnodes. for (short c = 0; c != m_count; c++) { buff[buffsize] = (byte)(m_min + c); if (m_next[c] != null) m_next[c].ApplyHelper(buff, buffsize + 1, maxbuffsize, func, arg); } }
// Apply the function supplied to each subscription in the trie. public void Apply(TrieDelegate func, Object arg) { ApplyHelper(null, 0, 0, func, arg); }
private void ApplyHelper( byte[] buffer, int bufferSize, int maxBufferSize, TrieDelegate func, object arg) { // If this node is a subscription, apply the function. if (m_referenceCount > 0) func(buffer, bufferSize, arg); // Adjust the buffer. if (bufferSize >= maxBufferSize) { maxBufferSize = bufferSize + 256; Array.Resize(ref buffer, maxBufferSize); Debug.Assert(buffer != null); } // If there are no subnodes in the trie, return. if (m_count == 0) return; // If there's one subnode (optimisation). if (m_count == 1) { buffer[bufferSize] = m_minCharacter; bufferSize++; m_next[0].ApplyHelper(buffer, bufferSize, maxBufferSize, func, arg); return; } // If there are multiple subnodes. for (short c = 0; c != m_count; c++) { buffer[bufferSize] = (byte)(m_minCharacter + c); if (m_next[c] != null) m_next[c].ApplyHelper(buffer, bufferSize + 1, maxBufferSize, func, arg); } }