Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions include/tscore/Trie.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@
#include "tscore/List.h"
#include "tscore/Diags.h"

class TrieImpl
{
protected:
inline static DbgCtl dbg_ctl_insert{"Trie::Insert"};
inline static DbgCtl dbg_ctl_search{"Trie::Search"};
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this so these only get constructed if a Trie does?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off the top of my head, I'm not sure. My guess would be it's unspecified behavior, up to the the particular C++ implementation.


// Note that you should provide the class to use here, but we'll store
// pointers to such objects internally.
template <typename T> class Trie
template <typename T> class Trie : private TrieImpl
{
public:
Trie() { m_root.Clear(); }
Expand Down Expand Up @@ -84,7 +91,7 @@ template <typename T> class Trie
ink_zero(children);
}

void Print(const char *debug_tag) const;
void Print(const DbgCtl &dbg_ctl) const;
inline Node *
GetChild(char index) const
{
Expand Down Expand Up @@ -142,9 +149,9 @@ Trie<T>::Insert(const char *key, T *value, int rank, int key_len /* = -1 */)
int i = 0;

while (true) {
if (is_debug_tag_set("Trie::Insert")) {
Debug("Trie::Insert", "Visiting Node...");
curr_node->Print("Trie::Insert");
if (is_dbg_ctl_enabled(dbg_ctl_insert)) {
Dbg(dbg_ctl_insert, "Visiting Node...");
curr_node->Print(dbg_ctl_insert);
}

if (i == key_len) {
Expand All @@ -154,7 +161,7 @@ Trie<T>::Insert(const char *key, T *value, int rank, int key_len /* = -1 */)
next_node = curr_node->GetChild(key[i]);
if (!next_node) {
while (i < key_len) {
Debug("Trie::Insert", "Creating child node for char %c (%d)", key[i], key[i]);
Dbg(dbg_ctl_insert, "Creating child node for char %c (%d)", key[i], key[i]);
curr_node = curr_node->AllocateChild(key[i]);
++i;
}
Expand All @@ -165,15 +172,15 @@ Trie<T>::Insert(const char *key, T *value, int rank, int key_len /* = -1 */)
}

if (curr_node->occupied) {
Debug("Trie::Insert", "Cannot insert duplicate!");
Dbg(dbg_ctl_insert, "Cannot insert duplicate!");
return false;
}

curr_node->occupied = true;
curr_node->value = value;
curr_node->rank = rank;
m_value_list.enqueue(curr_node->value);
Debug("Trie::Insert", "inserted new element!");
Dbg(dbg_ctl_insert, "inserted new element!");
return true;
}

Expand All @@ -188,9 +195,9 @@ Trie<T>::Search(const char *key, int key_len /* = -1 */) const
int i = 0;

while (curr_node) {
if (is_debug_tag_set("Trie::Search")) {
Debug("Trie::Search", "Visiting node...");
curr_node->Print("Trie::Search");
if (is_dbg_ctl_enabled(dbg_ctl_search)) {
DbgPrint(dbg_ctl_search, "Visiting node...");
curr_node->Print(dbg_ctl_search);
}
if (curr_node->occupied) {
if (!found_node || curr_node->rank <= found_node->rank) {
Expand All @@ -205,7 +212,7 @@ Trie<T>::Search(const char *key, int key_len /* = -1 */) const
}

if (found_node) {
Debug("Trie::Search", "Returning element with rank %d", found_node->rank);
Dbg(dbg_ctl_search, "Returning element with rank %d", found_node->rank);
return found_node->value;
}

Expand Down Expand Up @@ -250,18 +257,18 @@ Trie<T>::Print() const

template <typename T>
void
Trie<T>::Node::Print(const char *debug_tag) const
Trie<T>::Node::Print(const DbgCtl &dbg_ctl) const
{
if (occupied) {
Debug(debug_tag, "Node is occupied");
Debug(debug_tag, "Node has rank %d", rank);
Dbg(dbg_ctl, "Node is occupied");
Dbg(dbg_ctl, "Node has rank %d", rank);
} else {
Debug(debug_tag, "Node is not occupied");
Dbg(dbg_ctl, "Node is not occupied");
}

for (int i = 0; i < N_NODE_CHILDREN; ++i) {
if (GetChild(i)) {
Debug(debug_tag, "Node has child for char %c", static_cast<char>(i));
Dbg(dbg_ctl, "Node has child for char %c", static_cast<char>(i));
}
}
}
4 changes: 2 additions & 2 deletions iocore/aio/AIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ DiskHandler::mainAIOEvent(int event, Event *e)
if (errno == EINTR)
goto Lagain;
if (errno == EFAULT || errno == ENOSYS)
Debug("aio", "io_getevents failed: %s (%d)", strerror(-ret), -ret);
Dbg(_dbg_ctl_aio, "io_getevents failed: %s (%d)", strerror(-ret), -ret);
}

ink_aiocb *cbs[MAX_AIO_EVENTS];
Expand All @@ -658,7 +658,7 @@ DiskHandler::mainAIOEvent(int event, Event *e)

if (ret != num) {
if (ret < 0) {
Debug("aio", "io_submit failed: %s (%d)", strerror(-ret), -ret);
Dbg(_dbg_ctl_aio, "io_submit failed: %s (%d)", strerror(-ret), -ret);
} else {
Fatal("could not submit IOs, io_submit(%p, %d, %p) returned %d", ctx, num, cbs, ret);
}
Expand Down
5 changes: 4 additions & 1 deletion iocore/aio/I_AIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ struct DiskHandler : public Continuation {
memset(&ctx, 0, sizeof(ctx));
int ret = io_setup(MAX_AIO_EVENTS, &ctx);
if (ret < 0) {
Debug("aio", "io_setup error: %s (%d)", strerror(-ret), -ret);
Dbg(_dbg_ctl_aio, "io_setup error: %s (%d)", strerror(-ret), -ret);
}
}

private:
inline static DbgCtl _dbg_ctl_aio{"aio"};
};
#endif

Expand Down
Loading