diff options
-rw-r--r-- | src/mtrie.cpp | 42 | ||||
-rw-r--r-- | src/mtrie.hpp | 4 |
2 files changed, 31 insertions, 15 deletions
diff --git a/src/mtrie.cpp b/src/mtrie.cpp index ac1fc31..91f6852 100644 --- a/src/mtrie.cpp +++ b/src/mtrie.cpp @@ -52,6 +52,12 @@ zmq::mtrie_t::~mtrie_t () bool zmq::mtrie_t::add (unsigned char *prefix_, size_t size_, pipe_t *pipe_) { + return add_helper (prefix_, size_, pipe_); +} + +bool zmq::mtrie_t::add_helper (unsigned char *prefix_, size_t size_, + pipe_t *pipe_) +{ // We are at the node corresponding to the prefix. We are done. if (!size_) { bool result = pipes.empty (); @@ -114,14 +120,14 @@ bool zmq::mtrie_t::add (unsigned char *prefix_, size_t size_, pipe_t *pipe_) next.node = new (std::nothrow) mtrie_t; zmq_assert (next.node); } - return next.node->add (prefix_ + 1, size_ - 1, pipe_); + return next.node->add_helper (prefix_ + 1, size_ - 1, pipe_); } else { if (!next.table [c - min]) { next.table [c - min] = new (std::nothrow) mtrie_t; zmq_assert (next.table [c - min]); } - return next.table [c - min]->add (prefix_ + 1, size_ - 1, pipe_); + return next.table [c - min]->add_helper (prefix_ + 1, size_ - 1, pipe_); } } @@ -175,23 +181,29 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_, bool zmq::mtrie_t::rm (unsigned char *prefix_, size_t size_, pipe_t *pipe_) { - if (!size_) { - pipes_t::size_type erased = pipes.erase (pipe_); - zmq_assert (erased == 1); - return pipes.empty (); - } + return rm_helper (prefix_, size_, pipe_); +} - unsigned char c = *prefix_; - if (!count || c < min || c >= min + count) - return false; +bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, size_t size_, + pipe_t *pipe_) +{ + if (!size_) { + pipes_t::size_type erased = pipes.erase (pipe_); + zmq_assert (erased == 1); + return pipes.empty (); + } + + unsigned char c = *prefix_; + if (!count || c < min || c >= min + count) + return false; - mtrie_t *next_node = - count == 1 ? next.node : next.table [c - min]; + mtrie_t *next_node = + count == 1 ? next.node : next.table [c - min]; - if (!next_node) - return false; + if (!next_node) + return false; - return next_node->rm (prefix_ + 1, size_ - 1, pipe_); + return next_node->rm_helper (prefix_ + 1, size_ - 1, pipe_); } void zmq::mtrie_t::match (unsigned char *data_, size_t size_, pipes_t &pipes_) diff --git a/src/mtrie.hpp b/src/mtrie.hpp index 99f20e2..cd47029 100644 --- a/src/mtrie.hpp +++ b/src/mtrie.hpp @@ -60,10 +60,14 @@ namespace zmq private: + bool add_helper (unsigned char *prefix_, size_t size_, + class pipe_t *pipe_); void rm_helper (class pipe_t *pipe_, unsigned char **buff_, size_t buffsize_, size_t maxbuffsize_, void (*func_) (unsigned char *data_, size_t size_, void *arg_), void *arg_); + bool rm_helper (unsigned char *prefix_, size_t size_, + class pipe_t *pipe_); pipes_t pipes; unsigned char min; |