Unverified Commit d5067df2 authored by Luca Boccassi's avatar Luca Boccassi Committed by GitHub

Merge pull request #3559 from ssbl/inconsistent-naming-convention-fix

Problem: code doesn't follow libzmq naming conventions
parents 4a855fba 1186e986
...@@ -48,28 +48,28 @@ const char *chars = "abcdefghijklmnopqrstuvwxyz0123456789"; ...@@ -48,28 +48,28 @@ const char *chars = "abcdefghijklmnopqrstuvwxyz0123456789";
const int chars_len = 36; const int chars_len = 36;
template <class T> template <class T>
void benchmark_lookup (T &t, void benchmark_lookup (T &subscriptions_,
std::vector<unsigned char *> &input_set, std::vector<unsigned char *> &input_set_,
std::vector<unsigned char *> &queries) std::vector<unsigned char *> &queries_)
{ {
using namespace std::chrono; using namespace std::chrono;
std::vector<duration<long, std::nano>> samples_vec; std::vector<duration<long, std::nano>> samples_vec;
samples_vec.reserve (samples); samples_vec.reserve (samples);
for (std::size_t run = 0; run < warmup_runs; ++run) { for (std::size_t run = 0; run < warmup_runs; ++run) {
for (auto &query : queries) for (auto &query : queries_)
t.check (query, key_length); subscriptions_.check (query, key_length);
} }
for (std::size_t run = 0; run < samples; ++run) { for (std::size_t run = 0; run < samples; ++run) {
duration<long, std::nano> interval (0); duration<long, std::nano> interval (0);
for (auto &query : queries) { for (auto &query : queries_) {
auto start = steady_clock::now (); auto start = steady_clock::now ();
t.check (query, key_length); subscriptions_.check (query, key_length);
auto end = steady_clock::now (); auto end = steady_clock::now ();
interval += end - start; interval += end - start;
} }
samples_vec.push_back (interval / queries.size ()); samples_vec.push_back (interval / queries_.size ());
} }
std::size_t sum = 0; std::size_t sum = 0;
...@@ -102,7 +102,7 @@ int main () ...@@ -102,7 +102,7 @@ int main ()
// Keeping initialization out of the benchmarking function helps // Keeping initialization out of the benchmarking function helps
// heaptrack detect peak memory consumption of the radix tree. // heaptrack detect peak memory consumption of the radix tree.
zmq::trie_t trie; zmq::trie_t trie;
zmq::radix_tree radix_tree; zmq::radix_tree_t radix_tree;
for (auto &key : input_set) { for (auto &key : input_set) {
trie.add (key, key_length); trie.add (key, key_length);
radix_tree.add (key, key_length); radix_tree.add (key, key_length);
......
This diff is collapsed.
...@@ -62,62 +62,62 @@ ...@@ -62,62 +62,62 @@
// of the chunk of first bytes and node pointers respectively. // of the chunk of first bytes and node pointers respectively.
struct node_t struct node_t
{ {
unsigned char *data_; explicit node_t (unsigned char *data_);
explicit node_t (unsigned char *data); bool operator== (node_t other_) const;
bool operator!= (node_t other_) const;
bool operator== (node_t other) const;
bool operator!= (node_t other) const;
inline uint32_t refcount (); inline uint32_t refcount ();
inline uint32_t prefix_length (); inline uint32_t prefix_length ();
inline uint32_t edgecount (); inline uint32_t edgecount ();
inline unsigned char *prefix (); inline unsigned char *prefix ();
inline unsigned char *first_bytes (); inline unsigned char *first_bytes ();
inline unsigned char first_byte_at (size_t index); inline unsigned char first_byte_at (size_t index_);
inline unsigned char *node_pointers (); inline unsigned char *node_pointers ();
inline node_t node_at (size_t index); inline node_t node_at (size_t index_);
inline void set_refcount (uint32_t value); inline void set_refcount (uint32_t value_);
inline void set_prefix_length (uint32_t value); inline void set_prefix_length (uint32_t value_);
inline void set_edgecount (uint32_t value); inline void set_edgecount (uint32_t value_);
inline void set_prefix (const unsigned char *prefix); inline void set_prefix (const unsigned char *prefix_);
inline void set_first_bytes (const unsigned char *bytes); inline void set_first_bytes (const unsigned char *bytes_);
inline void set_first_byte_at (size_t index, unsigned char byte); inline void set_first_byte_at (size_t index_, unsigned char byte_);
inline void set_node_pointers (const unsigned char *pointers); inline void set_node_pointers (const unsigned char *pointers_);
inline void set_node_at (size_t index, node_t node); inline void set_node_at (size_t index_, node_t node_);
inline void inline void
set_edge_at (size_t index, unsigned char first_byte, node_t node); set_edge_at (size_t index_, unsigned char first_byte_, node_t node_);
void resize (size_t prefix_length, size_t edgecount); void resize (size_t prefix_length_, size_t edgecount_);
unsigned char *_data;
}; };
node_t make_node (size_t refcount, size_t prefix_length, size_t edgecount); node_t make_node (size_t refcount_, size_t prefix_length_, size_t edgecount_);
struct match_result_t struct match_result_t
{ {
size_t key_bytes_matched; match_result_t (size_t key_bytes_matched_,
size_t prefix_bytes_matched; size_t prefix_bytes_matched_,
size_t edge_index; size_t edge_index_,
size_t parent_edge_index; size_t parent_edge_index_,
node_t current_node; node_t current_,
node_t parent_node; node_t parent_,
node_t grandparent_node;
match_result_t (size_t key_bytes_matched,
size_t prefix_bytes_matched,
size_t edge_index,
size_t parent_edge_index,
node_t current,
node_t parent,
node_t grandparent); node_t grandparent);
size_t _key_bytes_matched;
size_t _prefix_bytes_matched;
size_t _edge_index;
size_t _parent_edge_index;
node_t _current_node;
node_t _parent_node;
node_t _grandparent_node;
}; };
namespace zmq namespace zmq
{ {
class radix_tree class radix_tree_t
{ {
public: public:
radix_tree (); radix_tree_t ();
~radix_tree (); ~radix_tree_t ();
// Add key to the tree. Returns true if this was a new key rather // Add key to the tree. Returns true if this was a new key rather
// than a duplicate. // than a duplicate.
...@@ -138,10 +138,10 @@ class radix_tree ...@@ -138,10 +138,10 @@ class radix_tree
private: private:
inline match_result_t inline match_result_t
match (const unsigned char *key, size_t key_size, bool is_lookup) const; match (const unsigned char *key_, size_t key_size_, bool is_lookup_) const;
node_t root_; node_t _root;
size_t size_; size_t _size;
}; };
} }
......
...@@ -83,7 +83,7 @@ class xsub_t : public socket_base_t ...@@ -83,7 +83,7 @@ class xsub_t : public socket_base_t
// The repository of subscriptions. // The repository of subscriptions.
#ifdef ZMQ_USE_RADIX_TREE #ifdef ZMQ_USE_RADIX_TREE
radix_tree _subscriptions; radix_tree_t _subscriptions;
#else #else
trie_t _subscriptions; trie_t _subscriptions;
#endif #endif
......
...@@ -35,41 +35,41 @@ void tearDown () ...@@ -35,41 +35,41 @@ void tearDown ()
{ {
} }
bool tree_add (zmq::radix_tree &tree, const std::string &key) bool tree_add (zmq::radix_tree_t &tree_, const std::string &key_)
{ {
return tree.add (reinterpret_cast<const unsigned char *> (key.data ()), return tree_.add (reinterpret_cast<const unsigned char *> (key_.data ()),
key.size ()); key_.size ());
} }
bool tree_rm (zmq::radix_tree &tree, const std::string &key) bool tree_rm (zmq::radix_tree_t &tree_, const std::string &key_)
{ {
return tree.rm (reinterpret_cast<const unsigned char *> (key.data ()), return tree_.rm (reinterpret_cast<const unsigned char *> (key_.data ()),
key.size ()); key_.size ());
} }
bool tree_check (zmq::radix_tree &tree, const std::string &key) bool tree_check (zmq::radix_tree_t &tree_, const std::string &key_)
{ {
return tree.check (reinterpret_cast<const unsigned char *> (key.data ()), return tree_.check (reinterpret_cast<const unsigned char *> (key_.data ()),
key.size ()); key_.size ());
} }
void test_empty () void test_empty ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
TEST_ASSERT_TRUE (tree.size () == 0); TEST_ASSERT_TRUE (tree.size () == 0);
} }
void test_add_single_entry () void test_add_single_entry ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
TEST_ASSERT_TRUE (tree_add (tree, "foo")); TEST_ASSERT_TRUE (tree_add (tree, "foo"));
} }
void test_add_same_entry_twice () void test_add_same_entry_twice ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
TEST_ASSERT_TRUE (tree_add (tree, "test")); TEST_ASSERT_TRUE (tree_add (tree, "test"));
TEST_ASSERT_FALSE (tree_add (tree, "test")); TEST_ASSERT_FALSE (tree_add (tree, "test"));
...@@ -77,14 +77,14 @@ void test_add_same_entry_twice () ...@@ -77,14 +77,14 @@ void test_add_same_entry_twice ()
void test_rm_when_empty () void test_rm_when_empty ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
TEST_ASSERT_FALSE (tree_rm (tree, "test")); TEST_ASSERT_FALSE (tree_rm (tree, "test"));
} }
void test_rm_single_entry () void test_rm_single_entry ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
tree_add (tree, "temporary"); tree_add (tree, "temporary");
TEST_ASSERT_TRUE (tree_rm (tree, "temporary")); TEST_ASSERT_TRUE (tree_rm (tree, "temporary"));
...@@ -92,7 +92,7 @@ void test_rm_single_entry () ...@@ -92,7 +92,7 @@ void test_rm_single_entry ()
void test_rm_unique_entry_twice () void test_rm_unique_entry_twice ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
tree_add (tree, "test"); tree_add (tree, "test");
TEST_ASSERT_TRUE (tree_rm (tree, "test")); TEST_ASSERT_TRUE (tree_rm (tree, "test"));
...@@ -101,7 +101,7 @@ void test_rm_unique_entry_twice () ...@@ -101,7 +101,7 @@ void test_rm_unique_entry_twice ()
void test_rm_duplicate_entry () void test_rm_duplicate_entry ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
tree_add (tree, "test"); tree_add (tree, "test");
tree_add (tree, "test"); tree_add (tree, "test");
...@@ -111,7 +111,7 @@ void test_rm_duplicate_entry () ...@@ -111,7 +111,7 @@ void test_rm_duplicate_entry ()
void test_rm_common_prefix () void test_rm_common_prefix ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
tree_add (tree, "checkpoint"); tree_add (tree, "checkpoint");
tree_add (tree, "checklist"); tree_add (tree, "checklist");
...@@ -120,7 +120,7 @@ void test_rm_common_prefix () ...@@ -120,7 +120,7 @@ void test_rm_common_prefix ()
void test_rm_common_prefix_entry () void test_rm_common_prefix_entry ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
tree_add (tree, "checkpoint"); tree_add (tree, "checkpoint");
tree_add (tree, "checklist"); tree_add (tree, "checklist");
...@@ -130,7 +130,7 @@ void test_rm_common_prefix_entry () ...@@ -130,7 +130,7 @@ void test_rm_common_prefix_entry ()
void test_rm_null_entry () void test_rm_null_entry ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
tree_add (tree, ""); tree_add (tree, "");
TEST_ASSERT_TRUE (tree_rm (tree, "")); TEST_ASSERT_TRUE (tree_rm (tree, ""));
...@@ -138,14 +138,14 @@ void test_rm_null_entry () ...@@ -138,14 +138,14 @@ void test_rm_null_entry ()
void test_check_empty () void test_check_empty ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
TEST_ASSERT_FALSE (tree_check (tree, "foo")); TEST_ASSERT_FALSE (tree_check (tree, "foo"));
} }
void test_check_added_entry () void test_check_added_entry ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
tree_add (tree, "entry"); tree_add (tree, "entry");
TEST_ASSERT_TRUE (tree_check (tree, "entry")); TEST_ASSERT_TRUE (tree_check (tree, "entry"));
...@@ -153,7 +153,7 @@ void test_check_added_entry () ...@@ -153,7 +153,7 @@ void test_check_added_entry ()
void test_check_common_prefix () void test_check_common_prefix ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
tree_add (tree, "introduce"); tree_add (tree, "introduce");
tree_add (tree, "introspect"); tree_add (tree, "introspect");
...@@ -162,7 +162,7 @@ void test_check_common_prefix () ...@@ -162,7 +162,7 @@ void test_check_common_prefix ()
void test_check_prefix () void test_check_prefix ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
tree_add (tree, "toasted"); tree_add (tree, "toasted");
TEST_ASSERT_FALSE (tree_check (tree, "toast")); TEST_ASSERT_FALSE (tree_check (tree, "toast"));
...@@ -172,7 +172,7 @@ void test_check_prefix () ...@@ -172,7 +172,7 @@ void test_check_prefix ()
void test_check_nonexistent_entry () void test_check_nonexistent_entry ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
tree_add (tree, "red"); tree_add (tree, "red");
TEST_ASSERT_FALSE (tree_check (tree, "blue")); TEST_ASSERT_FALSE (tree_check (tree, "blue"));
...@@ -180,7 +180,7 @@ void test_check_nonexistent_entry () ...@@ -180,7 +180,7 @@ void test_check_nonexistent_entry ()
void test_check_query_longer_than_entry () void test_check_query_longer_than_entry ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
tree_add (tree, "foo"); tree_add (tree, "foo");
TEST_ASSERT_TRUE (tree_check (tree, "foobar")); TEST_ASSERT_TRUE (tree_check (tree, "foobar"));
...@@ -188,7 +188,7 @@ void test_check_query_longer_than_entry () ...@@ -188,7 +188,7 @@ void test_check_query_longer_than_entry ()
void test_check_null_entry_added () void test_check_null_entry_added ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
tree_add (tree, ""); tree_add (tree, "");
TEST_ASSERT_TRUE (tree_check (tree, "all queries return true")); TEST_ASSERT_TRUE (tree_check (tree, "all queries return true"));
...@@ -196,7 +196,7 @@ void test_check_null_entry_added () ...@@ -196,7 +196,7 @@ void test_check_null_entry_added ()
void test_size () void test_size ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
// Adapted from the example on wikipedia. // Adapted from the example on wikipedia.
std::vector<std::string> keys; std::vector<std::string> keys;
...@@ -234,7 +234,7 @@ void return_key (unsigned char *data, size_t size, void *arg) ...@@ -234,7 +234,7 @@ void return_key (unsigned char *data, size_t size, void *arg)
void test_apply () void test_apply ()
{ {
zmq::radix_tree tree; zmq::radix_tree_t tree;
std::set<std::string> keys; std::set<std::string> keys;
keys.insert ("tester"); keys.insert ("tester");
......
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