#include <cstring>
#include <experimental/type_traits>
#include <functional>
-#include <iosfwd>
#include <iterator>
#include <limits>
#include <new>
return compare_result_as_less_than(key_comp()(x, y));
}
- // Dump the btree to the specified ostream. Requires that operator<< is
- // defined for Key and Value.
- void dump(std::ostream &os) const {
- if (root() != NULL) {
- internal_dump(os, root(), 0);
- }
- }
-
// Verifies the structure of the btree.
void verify() const;
// Deletes a node and all of its children.
void internal_clear(node_type *node);
- // Dumps a node and all of its children to the specified ostream.
- void internal_dump(std::ostream &os, const node_type *node, int level) const;
-
// Verifies the tree structure of node.
int internal_verify(const node_type *node,
const key_type *lo, const key_type *hi) const;
}
}
-template <typename P>
-void btree<P>::internal_dump(
- std::ostream &os, const node_type *node, int level) const {
- for (int i = 0; i < node->count(); ++i) {
- if (!node->leaf()) {
- internal_dump(os, node->child(i), level + 1);
- }
- for (int j = 0; j < level; ++j) {
- os << " ";
- }
- os << node->key(i) << " [" << level << "]\n";
- }
- if (!node->leaf()) {
- internal_dump(os, node->child(node->count()), level + 1);
- }
-}
-
template <typename P>
int btree<P>::internal_verify(
const node_type *node, const key_type *lo, const key_type *hi) const {
void clear() { tree_.clear(); }
void swap(btree_container &x) { tree_.swap(x.tree_); }
void verify() const { tree_.verify(); }
- void dump(std::ostream &os) const { tree_.dump(os); }
// Size routines.
size_type size() const { return tree_.size(); }
Tree tree_;
};
-template <typename T>
-inline std::ostream& operator<<(std::ostream &os, const btree_container<T> &b) {
- b.dump(os);
- return os;
-}
-
// A common base class for btree_set and btree_map.
template <typename Tree>
class btree_set_container : public btree_container<Tree> {