cheshirekow  v0.1.0
example_traits.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
25 #ifndef MPBLOCKS_RED_BLACK_EXAMPLETRAITS_H_
26 #define MPBLOCKS_RED_BLACK_EXAMPLETRAITS_H_
27 
29 #include <mpblocks/redblack/node.h>
30 #include <utility>
31 
32 namespace mpblocks {
33 namespace redblack {
34 
37 struct ExampleTraits {
42  typedef double Key;
43 
47 
50  typedef Node* NodeRef;
51 
54  struct NodeOps {
56  Color& color( NodeRef N ){ return N->color; }
57 
59  NodeRef& parent( NodeRef N ){ return N->parent; }
60 
62  NodeRef& left( NodeRef N ){ return N->left; }
63 
65  NodeRef& right( NodeRef N ){ return N->right; }
66 
68  Key& key( NodeRef N ){ return N->key; }
69 
71  void swapKey(NodeRef a, NodeRef b) { std::swap(a->key, b->key); }
72 };
73 };
74 
75 } //< namespace redblack
76 } //< namespace mpblocks
77 
78 #endif // MPBLOCKS_RED_BLACK_EXAMPLETRAITS_H_
Node * NodeRef
some type which stores uniquely identifies nodes, for instance a node pointer or an index into an arr...
an example traits struction from which a red-black tree may be instantiated
NodeRef & left(NodeRef N)
return the left child of N
A node in a redblack tree.
Definition: node.h:36
double Key
the key type, must be comparable, note that this typedef is not required, the tree will operate on wh...
Color & color(NodeRef N)
return the color of node N
NodeRef & right(NodeRef N)
return the right child of N
NodeRef & parent(NodeRef N)
return the parent node of N
BasicNode< ExampleTraits > Node
this type is not required by the interface, but if you just need a simple node type then this one wil...
a callable type which implements the primitives required to access fields of a node ...
Key & key(NodeRef N)
return the key associated with N
void swapKey(NodeRef a, NodeRef b)
swap the keys in two nodes