cheshirekow  v0.1.0
iterator.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_ITERATOR_H_
26 #define MPBLOCKS_RED_BLACK_ITERATOR_H_
27 
28 #include <iterator>
29 
30 namespace mpblocks {
31 namespace redblack {
32 
33 template< class Traits >
34 struct Tree;
35 
37 template <class Traits>
38 struct Iterator {
39  typedef typename Traits::NodeRef NodeRef;
41 
44 
46  auto operator*() -> decltype(tree->key(node)) { return tree->key(node); }
47 
48  Iterator(Tree_t* tree, NodeRef node) : tree(tree), node(node) {}
49 
53  return *this;
54  }
55 
59  return *this;
60  }
61 
63  bool operator!=(const Iterator& other) { return node != other.node; }
64 };
65 
66 } //< namespace redblack
67 } //< namespace mpblocks
68 
69 #endif // ITERATOR_H_
Iterator< Traits > & operator++()
increment operator
Definition: iterator.h:51
NodeRef treePredecessor(NodeRef x)
CLRS 12.2 page 259.
Definition: tree.h:251
bool operator!=(const Iterator &other)
comparison for range-based
Definition: iterator.h:63
Iterator(Tree_t *tree, NodeRef node)
Definition: iterator.h:48
auto operator*() -> decltype(tree->key(node))
dereference to whatever key returns
Definition: iterator.h:46
auto key(NodeRef N) -> decltype(m_ops.key(N))
Definition: tree.h:67
NodeRef treeSuccessor(NodeRef x)
CLRS 12.2 page 259.
Definition: tree.h:240
Tree< Traits > Tree_t
Definition: iterator.h:40
Iterator< Traits > & operator--()
decrement operator
Definition: iterator.h:57
implements red black trees from CLRS
Definition: iterator.h:38
BinaryKey other(const BinaryKey &key)
Definition: BinaryKey.h:44
Traits::NodeRef NodeRef
Definition: iterator.h:39
implements red black trees from CLRS
Definition: iterator.h:34