libUTL++
SkipListIt.h
1 #pragma once
2 
4 
5 #include <libutl/BidIt.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
20 
22 class SkipListIt : public BidIt
23 {
25 
26 public:
33  SkipListIt(const SkipList* skipList, SkipListNode* node, SkipListNode** update = nullptr)
34  : _skipList(const_cast<SkipList*>(skipList))
35  , _node(node)
36  , _update(update)
37  {
38  IFDEBUG(FwdIt::setOwner(_skipList));
39  }
40 
42  virtual int compare(const Object& rhs) const;
43 
45  virtual void copy(const Object& rhs);
46 
47  virtual void forward(size_t dist = 1);
48 
49  virtual Object* get() const;
50 
52  SkipList*
53  skipList() const
54  {
55  return _skipList;
56  }
57 
60  node() const
61  {
62  return _node;
63  }
64 
66  SkipListNode**
67  update() const
68  {
69  return _update;
70  }
71 
72  virtual void reverse(size_t dist = 1);
73 
74  virtual void set(const Object* object);
75 
81  void
82  set(const SkipList* skipList, SkipListNode* node)
83  {
84  _skipList = const_cast<SkipList*>(skipList);
85  _node = node;
86  IFDEBUG(FwdIt::setOwner(_skipList));
87  }
88 
90  void
92  {
93  _node = node;
94  }
95 
96  SkipListIt& operator++()
97  {
98  forward();
99  return *this;
100  }
101 
102  SkipListIt operator++(int)
103  {
104  SkipListIt res = *this;
105  forward();
106  return res;
107  }
108 
109  SkipListIt& operator--()
110  {
111  reverse();
112  return *this;
113  }
114 
115  SkipListIt operator--(int)
116  {
117  SkipListIt res = *this;
118  reverse();
119  return res;
120  }
121 
122 private:
123  void
124  init()
125  {
126  _skipList = nullptr;
127  _node = nullptr;
128  _update = nullptr;
129  }
130  void
131  deInit()
132  {
133  if (_update != nullptr) delete[] _update;
134  }
135 
136 private:
137  SkipList* _skipList;
138  SkipListNode* _node;
139  SkipListNode** _update;
140 };
141 
143 
145 SkipList::begin() const
146 {
147  iterator it(this, _head);
148  IFDEBUG(it.setConst(true));
149  return it;
150 }
151 
153 
155 SkipList::begin()
156 {
157  return iterator(this, _head->next());
158 }
159 
161 
162 BidIt*
163 SkipList::beginNew() const
164 {
165  BidIt* it = new iterator(this, _head->next());
166  IFDEBUG(it->setConst(true));
167  return it;
168 }
169 
171 
172 BidIt*
173 SkipList::beginNew()
174 {
175  return new iterator(this, _head->next());
176 }
177 
179 
181 SkipList::end() const
182 {
183  iterator it(this, _tail);
184  IFDEBUG(it.setConst(true));
185  return it;
186 }
187 
189 
191 SkipList::end()
192 {
193  return iterator(this, _tail);
194 }
195 
197 
198 BidIt*
199 SkipList::endNew() const
200 {
201  BidIt* it = new iterator(this, _tail);
202  IFDEBUG(it->setConst(true));
203  return it;
204 }
205 
207 
208 BidIt*
209 SkipList::endNew()
210 {
211  return new iterator(this, _tail);
212 }
213 
215 
216 UTL_NS_END;
void setNode(SkipListNode *node)
Set the skip-list node.
Definition: SkipListIt.h:91
void deInit()
De-initialize UTL++.
SkipListNode ** update() const
Get the update array.
Definition: SkipListIt.h:67
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
void reverse(const BidIt &begin, const BidIt &end)
Reverse a sequence.
Templated proxy for BidIt.
Definition: TBidIt.h:19
#define IFDEBUG(x)
Do x in DEBUG mode only.
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
Definition: util_inl.h:690
SkipList node.
Definition: SkipListNode.h:30
Skip list.
Definition: SkipList.h:51
void setConst(bool p_const)
Set the const flag.
Definition: FwdIt.h:68
Bi-directional iterator abstraction.
Definition: BidIt.h:25
SkipList * skipList() const
Get the associated SkipList.
Definition: SkipListIt.h:53
Bi-directional SkipList iterator.
Definition: SkipListIt.h:22
SkipListIt(const SkipList *skipList, SkipListNode *node, SkipListNode **update=nullptr)
Constructor.
Definition: SkipListIt.h:33
Root of UTL++ class hierarchy.
Definition: Object.h:52
int compare(bool lhs, bool rhs)
Compare two boolean values.
void init()
Initialize UTL++.
SkipListNode * node() const
Get the list node.
Definition: SkipListIt.h:60