libUTL++
TSkipList.h
1 #pragma once
2 
4 
5 #include <libutl/TSkipListIt.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
22 
24 template <class T>
25 class TSkipList : public SkipList
26 {
29 
30 public:
37  TSkipList(bool owner, bool multiSet = true, Ordering* ordering = nullptr);
38 
39  bool
40  add(const T& object)
41  {
42  return super::add(const_cast<T&>(object));
43  }
44 
45  bool
46  add(const T* object)
47  {
48  return super::add(const_cast<T*>(object));
49  }
50 
51  void
52  add(const Collection& collection)
53  {
54  super::add(collection);
55  }
56 
58  begin() const
59  {
60  TSkipListIt<T> res;
61  res.copy(SkipList::begin());
62  return res;
63  }
64 
66  begin()
67  {
68  TSkipListIt<T> res;
69  res.copy(SkipList::begin());
70  return res;
71  }
72 
74  end() const
75  {
76  TSkipListIt<T> res;
77  res.copy(SkipList::end());
78  return res;
79  }
80 
82  end()
83  {
84  TSkipListIt<T> res;
85  res.copy(SkipList::end());
86  return res;
87  }
88 
90  T*
91  findT(const Object& key) const
92  {
93  return utl::cast<T>(SkipList::find(key));
94  }
95 
97  findIt(const Object& key) const
98  {
99  TSkipListIt<T> res;
100  res.copy(SkipList::findIt(key));
101  return res;
102  }
103 
105  findIt(const Object& key)
106  {
107  TSkipListIt<T> res;
108  res.copy(SkipList::findIt(key));
109  return res;
110  }
111 
112  void
113  findFirstIt(const Object& key, BidIt& it, bool insert = false) const
114  {
115  super::findFirstIt(key, it);
116  }
117 
118  virtual void
119  findFirstIt(const Object& key, BidIt& it, bool insert = false)
120  {
121  super::findFirstIt(key, it, insert);
122  }
123 
125  findFirstIt(const Object& key, bool insert = false) const
126  {
127  TSkipListIt<T> res;
128  res.copy(SkipList::findFirstIt(key, insert));
129  return res;
130  }
131 
133  findFirstIt(const Object& key, bool insert = false)
134  {
135  TSkipListIt<T> res;
136  res.copy(SkipList::findFirstIt(key, insert));
137  return res;
138  }
139 
140  void
141  findLastIt(const Object& key, BidIt& it) const
142  {
143  super::findLastIt(key, it);
144  }
145 
146  virtual void
147  findLastIt(const Object& key, BidIt& it)
148  {
149  super::findLastIt(key, it);
150  }
151 
153  findLastIt(const Object& key) const
154  {
155  TSkipListIt<T> res;
156  res.copy(SkipList::findLastIt(key));
157  return res;
158  }
159 
161  findLastIt(const Object& key)
162  {
163  TSkipListIt<T> res;
164  res.copy(SkipList::findLastIt(key));
165  return res;
166  }
167 
168  bool
169  remove(const Object& key)
170  {
171  return super::remove(key);
172  }
173 
174 public:
175  typedef T type;
176  typedef TSkipListIt<T> iterator;
177  typedef T* value_type; // for STL
178 };
179 
181 
182 template <class T>
183 TSkipList<T>::TSkipList(bool owner, bool multiSet, Ordering* ordering)
184  : SkipList(owner, multiSet, ordering)
185 {
186 }
187 
189 
190 UTL_NS_END;
191 
193 
#define UTL_CLASS_IMPL_TPL(className, T)
Implementation of standard UTL++ functionality for a template class.
Definition: macros.h:906
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
Definition: macros.h:532
virtual void copy(const Object &rhs)
Copy another SkipListIt.
Object comparison abstraction.
Definition: Ordering.h:30
virtual void findFirstIt(const Object &key, BidIt &it, bool insert=false)
Find the first object matching the given key.
Definition: TSkipList.h:119
void remove(FwdIt &begin, const FwdIt &end, bool cmp=false, const Predicate *pred=nullptr, bool predVal=false)
Remove objects from a sequence.
Template version of SkipList.
Definition: TSkipList.h:25
Templated proxy for BidIt.
Definition: TBidIt.h:19
virtual void findLastIt(const Object &key, BidIt &it)
Find the last object matching the given key.
Definition: TSkipList.h:147
Skip list.
Definition: SkipList.h:51
T * findT(const Object &key) const
See find().
Definition: TSkipList.h:91
Bi-directional iterator abstraction.
Definition: BidIt.h:25
#define UTL_CLASS_DECL_TPL(DC, T, BC)
Declaration of standard UTL++ functionality for a template class with one parameter.
Definition: macros.h:713
Template version of SkipListIt.
Definition: TSkipListIt.h:23
Root of UTL++ class hierarchy.
Definition: Object.h:52
A collection of objects.
Definition: Collection.h:62