5 #include <libutl/RBtree.h> 6 #include <libutl/Span.h> 54 template <
class T,
class D = T>
74 return add(
object.
clone());
79 virtual bool add(
const Object*
object);
85 virtual bool isMergeable(
const Object& lhs,
const Object& rhs)
const;
103 onAdd(
const Object&
object)
107 onRemove(
const Object&
object)
130 template <
class T,
class D>
134 auto& spanRef = utl::cast<Span<T, D>>(
object->getKey());
147 iterator it = this->findFirstIt(span);
149 while (it != this->end())
159 if (isMergeable(*
object, curObj))
174 if (!rhsSpan.
isNil())
177 Object* rhsObj = curObj.clone();
181 _rhsSpan.Span<T, D>::copy(rhsSpan);
201 span.
set(spanRef.begin() - 1, spanRef.begin());
202 it = this->findIt(span);
204 if (adjObj !=
nullptr)
206 if (isMergeable(*
object, *adjObj))
215 span.set(spanRef.end(), spanRef.end() + 1);
216 it = this->findIt(span);
218 if (adjObj !=
nullptr)
220 if (isMergeable(*
object, *adjObj))
229 _totalSize += spanRef.size();
238 template <
class T,
class D>
244 if (this->_items > 0)
254 template <
class T,
class D>
260 if (this->_items > 0)
270 template <
class T,
class D>
277 ((
Span<T, D>&)lhsSpan).Span<T, D>::copy(rhsSpan);
278 bool res = (lhs == rhs);
279 ((
Span<T, D>&)lhsSpan).Span<T, D>::copy(saveLHS);
285 template <
class T,
class D>
292 iterator it = this->findFirstIt(span);
294 while (it != this->end())
311 if (!rhsSpan.
isNil())
314 Object* rhsObj = curObj.clone();
318 _rhsSpan.Span<T, D>::copy(rhsSpan);
338 template <
class T,
class D>
344 lhsSpan.
merge(rhsSpan);
345 _totalSize -= rhsSpan.
size();
350 template <
class T,
class D>
356 _totalSize -= overlap.
size();
357 return objSpan.
remove(span);
T * clone(const T *object)
Create a clone of the given object.
void merge(const Span< T, D > &span)
Merge with the given span.
D totalSize() const
Get the total size of all spans.
void deInit()
De-initialize UTL++.
void merge(const FwdIt &lhsBegin, const FwdIt &lhsEnd, const FwdIt &rhsBegin, const FwdIt &rhsEnd, FwdIt &out, const Ordering *ordering=nullptr, bool cloning=false)
Merge two sorted sequences into a single sorted sequence.
D size() const
Return the size (end - begin).
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 RBtree.
#define UTL_CLASS_DECL_TPL2_TPLxTPL2(DC, DC_T1, DC_T2, BC, BC_BT, BC_T1, BC_T2)
Declaration of standard UTL++ functionality for a template class with two parameters, where the base class has one template parameter, which itself is a class with two template parameters.
virtual void set(const Object *object)
Set the current object.
In-order bi-directional BinTree iterator.
void setRelaxed(bool relaxed)
Set the relaxed flag.
#define UTL_CLASS_IMPL_TPL2(className, T1, T2)
Implementation of standard UTL++ functionality for a template class with two parameters.
Span< T, D > overlap(const Span< T, D > &span) const
Return the sub-span that overlaps with the given span.
virtual const Object & getKey() const
Get the key for this object.
bool isNil() const
Determine whether the span is nil.
Root of UTL++ class hierarchy.
Span< T, D > remove(const Span< T, D > &span)
Remove the given span from self.
void init()
Initialize UTL++.