Effective implementation of algorithms (Master Thesis)
Effective and error-free implementation of algorithms
|
00001 #ifndef H_BALANCED_STRUCTURES_SKIPLIST_SKIPLIST_ITERATOR 00002 #define H_BALANCED_STRUCTURES_SKIPLIST_SKIPLIST_ITERATOR 00003 00006 #include <iterator> 00007 00008 namespace balanced_structures { 00009 namespace skiplist { 00010 00011 // Forward definition of Node 00012 template<typename T> 00013 class Node; 00014 00018 template <typename T> 00019 struct ConstIterator : public std::iterator<std::bidirectional_iterator_tag, T> { 00020 typedef const T value_type; 00021 typedef const T& reference; 00022 typedef const T* pointer; 00023 typedef ConstIterator<T> self; 00024 00028 ConstIterator(): node(NULL) { 00029 } 00030 00034 explicit ConstIterator(Node<T>* x) : 00035 node(x) { 00036 } 00037 00041 reference operator*() const { 00042 Preconditions::checkNotNull(node); 00043 return node->value; 00044 } 00045 00049 Node<T>* getNode() { 00050 return node; 00051 } 00052 00056 self& operator++() { 00057 Preconditions::checkNotNull(node); 00058 node = node->next(); 00059 return *this; 00060 } 00061 00065 self operator++(int) { 00066 Preconditions::checkNotNull(node); 00067 self tmp = *this; 00068 node = node->next(); 00069 return tmp; 00070 } 00071 00075 self& operator--() { 00076 Preconditions::checkNotNull(node); 00077 node = node->prev(); 00078 return *this; 00079 } 00080 00084 self operator--(int) { 00085 Preconditions::checkNotNull(node); 00086 self tmp = *this; 00087 node = node->prev(); 00088 return tmp; 00089 } 00090 00094 bool operator==(const self& x) const { 00095 return node == x.node; 00096 } 00097 00101 bool operator!=(const self& x) const { 00102 return !(*this == x); 00103 } 00104 00105 private: 00106 Node<T>* node; 00107 }; 00108 00109 } // namespace skiplist 00110 } // namespace balanced_structures 00111 #endif