1/* 2 * Copyright (c) 2012 Google 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 18 unchanged lines hidden (view full) --- 27 * 28 * Authors: Gabe Black 29 */ 30 31#ifndef __BASE_TRIE_HH__ 32#define __BASE_TRIE_HH__ 33 34#include <cassert> |
35#include <iostream> |
36 37#include "base/cprintf.hh" 38#include "base/logging.hh" 39#include "base/types.hh" 40 41// Key has to be an integral type. 42template <class Key, class Value> 43class Trie --- 34 unchanged lines hidden (view full) --- 78 if (kids[0]) { 79 kids[0]->clear(); 80 delete kids[0]; 81 kids[0] = NULL; 82 } 83 } 84 85 void |
86 dump(std::ostream &os, int level) |
87 { 88 for (int i = 1; i < level; i++) { |
89 ccprintf(os, "|"); |
90 } 91 if (level == 0) |
92 ccprintf(os, "Root "); |
93 else |
94 ccprintf(os, "+ "); 95 ccprintf(os, "(%p, %p, %#X, %#X, %p)\n", 96 parent, this, key, mask, value); |
97 if (kids[0]) |
98 kids[0]->dump(os, level + 1); |
99 if (kids[1]) |
100 kids[1]->dump(os, level + 1); |
101 } 102 }; 103 104 protected: 105 Node head; 106 107 public: 108 typedef Node *Handle; --- 239 unchanged lines hidden (view full) --- 348 head.clear(); 349 } 350 351 /** 352 * A debugging method which prints the contents of this trie. 353 * @param title An identifying title to put in the dump header. 354 */ 355 void |
356 dump(const char *title, std::ostream &os=std::cout) |
357 { |
358 ccprintf(os, "**************************************************\n"); 359 ccprintf(os, "*** Start of Trie: %s\n", title); 360 ccprintf(os, "*** (parent, me, key, mask, value pointer)\n"); 361 ccprintf(os, "**************************************************\n"); 362 head.dump(os, 0); |
363 } 364}; 365 366#endif |