5 #include <libutl/RandUtils.h> 6 #include <libutl/SortedCollection.h> 7 #include <libutl/Vector.h> 122 typedef Object*
const* iterator;
138 bool multiSet =
true,
139 bool keepSorted =
false,
149 Array(
bool owner,
bool multiSet =
true,
bool keepSorted =
false,
Ordering* ordering =
nullptr);
153 virtual void steal(
Object& rhs);
157 virtual size_t innerAllocatedSize()
const;
172 get(
size_t idx)
const 181 return _array.size();
188 return (_firstNull != _array.size());
195 return getFlag(flg_keepSorted);
202 return getFlag(flg_sorted);
213 void removeHoles(
size_t low = 0,
size_t high =
size_t_max);
240 _array.reserve(minSize);
252 set(idx, isOwner() ?
object.clone() : &object, firstNull);
267 _array.setIncrement(increment);
274 setFlag(flg_keepSorted, keepSorted);
275 if (keepSorted) setFlag(flg_sorted,
true);
282 setFlag(flg_sorted, sorted);
283 if (!sorted) setFlag(flg_keepSorted,
false);
293 shuffle(
size_t low = 0,
size_t high =
size_t_max, randutils::mt19937_64_rng* rng =
nullptr);
317 size_t findIndex(
const Object& key,
327 iterator findIt(
const Object& key)
const;
332 super::findIt(key, it);
343 iterator findFirstIt(
const Object& key,
bool insert =
false)
const;
346 findFirstIt(
const Object& key,
BidIt& it,
bool insert)
const 352 virtual void findFirstIt(
const Object& key,
BidIt& it,
bool insert =
false);
359 iterator findLastIt(
const Object& key)
const;
368 virtual void findLastIt(
const Object& key,
BidIt& it);
376 return super::add(
object);
382 return add(
object, isKeptSorted());
391 bool add(
const Object*
object,
bool keepSorted);
396 super::add(collection);
404 void add(
size_t idx,
size_t num = 1);
415 add(idx, isOwner() ?
object.
clone() : &
object);
424 void add(
size_t idx,
const Object*
object);
427 insert(
const Object&
object, iterator it)
429 insert(isOwner() ?
object.
clone() : &
object, it);
432 void insert(
const Object*
object, iterator it);
437 return super::insert(
object, it);
440 virtual void insert(
const Object*
object,
const BidIt& it);
446 virtual void clear();
452 return remove(*key,
true,
true);
458 return remove(key,
true,
true);
468 bool remove(
const Object& key,
bool relocate,
bool preserveOrder =
true);
476 void remove(
size_t idx,
bool relocate =
true,
bool preserveOrder =
true);
484 void removeIt(iterator it,
bool relocate =
true,
bool preserveOrder =
true);
493 void removeIt(iterator begin, iterator end,
bool relocate =
true,
bool preserveOrder =
true);
495 virtual void removeIt(
BidIt& it);
497 virtual void removeIt(
BidIt& begin,
BidIt& end);
506 void removeItems(
size_t idx,
size_t num,
bool relocate =
true,
bool preserveOrder =
true);
517 void replace(iterator it,
const Object* newObject,
bool keepSorted =
true);
524 void replace(base_iterator& it,
const Object* newObject);
534 replace(this->begin() + idx, newObject);
546 return replace(&oldObject, newObject);
555 bool replace(
const Object* oldObject,
const Object* newObject);
568 _array.relocate(indexOf(destIt), indexOf(srcIt));
579 _array.relocate(destIdx, srcIdx);
588 return _array.begin();
597 inline virtual RandIt* beginNew()
const;
599 inline virtual RandIt* beginNew();
601 inline virtual RandIt* endNew()
const;
603 inline virtual RandIt* endNew();
606 indexOf(iterator it)
const 609 return it - this->begin();
614 isValid(iterator it)
const 616 return (it >= this->begin()) && (it <= this->end());
634 Object* operator[](
int idx)
const 636 return operator[]((
size_t)idx);
639 Object* operator[](
size_t idx)
644 Object* operator[](
int idx)
646 return operator[]((
size_t)idx);
649 #if UTL_HOST_WORDSIZE == 64 652 return operator[]((
size_t)idx);
656 return operator[]((
size_t)idx);
669 ASSERTD(_array[idx] !=
nullptr);
670 return *(_array[idx]);
673 Object& operator()(
size_t idx)
677 Object& operator()(
int idx)
const 679 return operator()((
size_t)idx);
681 Object& operator()(
int idx)
683 return operator()((
size_t)idx);
686 #if UTL_HOST_WORDSIZE == 64 689 return operator()((
size_t)idx);
693 return operator()((
size_t)idx);
700 return addOrFind(
object);
706 return *addOrFind(
object);
710 virtual void sanityCheck()
const;
714 void init(
size_t size = 4,
717 bool multiSet =
true,
718 bool keepSorted =
false,
722 iterator findIt(
const Object& key,
uint_t findType)
const;
724 void _remove(
size_t idx);
726 void setFirstNull(
size_t idx);
731 fixArraySize(_array.size());
734 void fixArraySize(
size_t size);
754 #include <libutl/ArrayIt.h> 755 #include <libutl/TArray.h> void setKeepSorted(bool keepSorted)
Set the keepSorted flag.
T * clone(const T *object)
Create a clone of the given object.
void setSorted(bool sorted)
Set the sorted flag.
size_t totalSize() const
Get the size of the array (which is only as large as needed).
bool isSorted() const
Return the sorted flag.
#define const_cast_this
Pointer to the object the method was invoked on (casting away const).
Object & operator()(size_t idx) const
Array access operator (returning reference instead of pointer).
void deInit()
De-initialize UTL++.
Random-access Array iterator.
Object comparison abstraction.
size_t firstNull() const
Return the index of the first null object in the array.
void sort(const FwdIt &begin, const FwdIt &end, const Ordering *ordering=nullptr, uint_t algorithm=sort_quickSort, size_t size=size_t_max)
Sort a sequence using a given algorithm.
void relocate(iterator destIt, iterator srcIt)
Relocate an object to a new position.
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
void relocate(size_t destIdx, size_t srcIdx)
Relocate an object to a new position.
void add(size_t idx, const Object &object)
Add an object at a given index.
void economize()
Make the allocation exactly large enough to contain the last non-null Object*.
Random-access iterator abstraction.
const size_t size_t_max
Maximum size_t value.
Object * operator[](size_t idx) const
Array access operator.
#define IFDEBUG(x)
Do x in DEBUG mode only.
SortedCollection that stores objects in an array.
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
Abstraction for a Collection whose objects may be sorted.
Object & operator()(const Object *object)
Add-or-find access operator (returns Object&).
bool isKeptSorted() const
Return the keepSorted flag.
void setConst(bool p_const)
Set the const flag.
unsigned int uint_t
Unsigned integer.
const uint_t uint_t_max
Maximum uint_t value.
Bi-directional iterator abstraction.
void excise()
Same as clear(), but in addition the Object*[] array is deleted.
virtual bool add(const Object *object)
Add an object to the collection.
A sequence of same-type objects.
void reserve(size_t minSize)
Reserve allocation space.
bool hasHole() const
Determine whether there are one or more "holes" in the array.
Object * operator[](const Object *object)
Add-or-find access operator (returns Object*).
bool replace(const Object &oldObject, const Object *newObject)
Replace oldObject with newObject.
Root of UTL++ class hierarchy.
void setIncrement(size_t increment)
Set the growth increment.
#define const_self
Reference to the object the method was invoked on (adding const qualifier).
void init()
Initialize UTL++.
#define ASSERTD
Do an assertion in DEBUG mode only.
void replace(size_t idx, const Object *newObject)
Replace object at idx with newObject.