Commit 3935258b authored by Martin Sustrik's avatar Martin Sustrik

Minor code beautification for mtrie_t

Signed-off-by: 's avatarMartin Sustrik <sustrik@250bpm.com>
parent ee7313b4
...@@ -51,6 +51,12 @@ zmq::mtrie_t::~mtrie_t () ...@@ -51,6 +51,12 @@ zmq::mtrie_t::~mtrie_t ()
} }
bool zmq::mtrie_t::add (unsigned char *prefix_, size_t size_, pipe_t *pipe_) 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. // We are at the node corresponding to the prefix. We are done.
if (!size_) { if (!size_) {
...@@ -114,14 +120,14 @@ bool zmq::mtrie_t::add (unsigned char *prefix_, size_t size_, pipe_t *pipe_) ...@@ -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; next.node = new (std::nothrow) mtrie_t;
zmq_assert (next.node); zmq_assert (next.node);
} }
return next.node->add (prefix_ + 1, size_ - 1, pipe_); return next.node->add_helper (prefix_ + 1, size_ - 1, pipe_);
} }
else { else {
if (!next.table [c - min]) { if (!next.table [c - min]) {
next.table [c - min] = new (std::nothrow) mtrie_t; next.table [c - min] = new (std::nothrow) mtrie_t;
zmq_assert (next.table [c - min]); 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_, ...@@ -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_) bool zmq::mtrie_t::rm (unsigned char *prefix_, size_t size_, pipe_t *pipe_)
{ {
if (!size_) { return rm_helper (prefix_, size_, pipe_);
pipes_t::size_type erased = pipes.erase (pipe_); }
zmq_assert (erased == 1);
return pipes.empty ();
}
unsigned char c = *prefix_; bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, size_t size_,
if (!count || c < min || c >= min + count) pipe_t *pipe_)
return false; {
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 = mtrie_t *next_node =
count == 1 ? next.node : next.table [c - min]; count == 1 ? next.node : next.table [c - min];
if (!next_node) if (!next_node)
return false; 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_) void zmq::mtrie_t::match (unsigned char *data_, size_t size_, pipes_t &pipes_)
......
...@@ -60,10 +60,14 @@ namespace zmq ...@@ -60,10 +60,14 @@ namespace zmq
private: private:
bool add_helper (unsigned char *prefix_, size_t size_,
class pipe_t *pipe_);
void rm_helper (class pipe_t *pipe_, unsigned char **buff_, void rm_helper (class pipe_t *pipe_, unsigned char **buff_,
size_t buffsize_, size_t maxbuffsize_, size_t buffsize_, size_t maxbuffsize_,
void (*func_) (unsigned char *data_, size_t size_, void *arg_), void (*func_) (unsigned char *data_, size_t size_, void *arg_),
void *arg_); void *arg_);
bool rm_helper (unsigned char *prefix_, size_t size_,
class pipe_t *pipe_);
pipes_t pipes; pipes_t pipes;
unsigned char min; unsigned char min;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment