trie.hh (12334:e0ab29a34764) | trie.hh (12335:4a2fde008219) |
---|---|
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> | 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> |
|
35 36#include "base/cprintf.hh" 37#include "base/logging.hh" 38#include "base/types.hh" 39 40// Key has to be an integral type. 41template <class Key, class Value> 42class Trie --- 34 unchanged lines hidden (view full) --- 77 if (kids[0]) { 78 kids[0]->clear(); 79 delete kids[0]; 80 kids[0] = NULL; 81 } 82 } 83 84 void | 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 |
85 dump(int level) | 86 dump(std::ostream &os, int level) |
86 { 87 for (int i = 1; i < level; i++) { | 87 { 88 for (int i = 1; i < level; i++) { |
88 cprintf("|"); | 89 ccprintf(os, "|"); |
89 } 90 if (level == 0) | 90 } 91 if (level == 0) |
91 cprintf("Root "); | 92 ccprintf(os, "Root "); |
92 else | 93 else |
93 cprintf("+ "); 94 cprintf("(%p, %p, %#X, %#X, %p)\n", parent, this, key, mask, value); | 94 ccprintf(os, "+ "); 95 ccprintf(os, "(%p, %p, %#X, %#X, %p)\n", 96 parent, this, key, mask, value); |
95 if (kids[0]) | 97 if (kids[0]) |
96 kids[0]->dump(level + 1); | 98 kids[0]->dump(os, level + 1); |
97 if (kids[1]) | 99 if (kids[1]) |
98 kids[1]->dump(level + 1); | 100 kids[1]->dump(os, level + 1); |
99 } 100 }; 101 102 protected: 103 Node head; 104 105 public: 106 typedef Node *Handle; --- 239 unchanged lines hidden (view full) --- 346 head.clear(); 347 } 348 349 /** 350 * A debugging method which prints the contents of this trie. 351 * @param title An identifying title to put in the dump header. 352 */ 353 void | 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 |
354 dump(const char *title) | 356 dump(const char *title, std::ostream &os=std::cout) |
355 { | 357 { |
356 cprintf("**************************************************\n"); 357 cprintf("*** Start of Trie: %s\n", title); 358 cprintf("*** (parent, me, key, mask, value pointer)\n"); 359 cprintf("**************************************************\n"); 360 head.dump(0); | 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); |
361 } 362}; 363 364#endif | 363 } 364}; 365 366#endif |