8 #ifndef INCL_evo_sublist_h 9 #define INCL_evo_sublist_h 144 template<
class T,
class TSize=SizeT>
205 if (data.
data_ == NULL) {
209 if (index > data.
size_)
211 const Size max_size = data.
size_ - index;
261 while (!(data[
size_] == term))
265 #if defined(EVO_CPP11) 270 ::memcpy(
this, &src,
sizeof(ThisType));
278 ::memcpy(
this, &src,
sizeof(ThisType));
299 ::memcpy(
this, &src,
sizeof(ThisType));
385 ThisType&
set(
const ListBaseType&
data) {
400 ThisType&
set(
const ListBaseType&
data, Key index, Key
size=
ALL) {
401 if (data.data_ == NULL) {
405 if (index > data.size_)
407 const Size max_size = data.size_ - index;
408 data_ = (Item*)data.data_ + index;
409 size_ = (size > max_size ? max_size : size);
421 ThisType&
set(
const ListBaseType*
data) {
450 ThisType&
set2(
const ListBaseType& data, Key index1, Key index2) {
451 if (data.
data_ == NULL) {
455 if (index1 > data.
size_)
458 if (index2 > data.
size_)
460 else if (index2 <= index1)
463 size_ = index2 - index1;
478 {
return (
data_ == NULL); }
482 {
return (
size_ == 0); }
512 assert( index <
size_ );
522 const Item&
item(Key index)
const {
523 assert( index <
size_ );
549 result = (data.
data_ != NULL ? -1 : 0);
550 else if (data.
data_ == NULL)
561 result = (data.
data_ == NULL);
562 else if (data.
data_ == NULL)
573 result = (data.
data_ != NULL);
574 else if (data.
data_ == NULL)
586 bool starts(
const Item* items, Size size)
const 590 bool starts(
const ListBaseType& items)
const 598 bool ends(
const Item* items, Size size)
const 602 bool ends(
const ListBaseType& items)
const 614 {
return Iter(*
this); }
633 {
return Iter(*
this); }
649 for (; start<
end; ++start)
650 if (
data_[start] == item)
666 Key
findany(
const Item* items, Size count, Key start=0, Key
end=
END)
const {
670 for (; start<
end; ++start)
671 for (j=0; j<count; ++j)
672 if (
data_[start] == items[j])
684 for (j=0; j<count; ++j)
694 for (Key i=0; i<
size_; ++i)
695 if (
data_[i] == item)
696 { result =
true;
break; }
703 if (size > 0 &&
size_ >= size) {
705 for (Key i=0; i<=
end; ++i)
707 { result =
true;
break; }
717 for (Key i=0; i<=
end; ++i)
719 { result =
true;
break; }
727 template<
class T1,
class T2>
728 bool splitat(Key index, T1& left, T2& right)
const {
730 if (index >=
size_) {
734 left.set(*
this, 0, index);
735 right.set(*
this, index+1,
size_-index-1);
748 left.set(*
this, 0, index);
762 right.set(*
this, index+1,
size_-index-1);
782 if (index >=
size_) {
785 right.set(*
this, index+1,
size_-index-1);
808 if (index >=
size_) {
812 left.set(*
this, 0, index);
826 }
else if (
size_ > 0) {
837 }
else if (
size_ > 0) {
867 }
else if (
size_ > 0) {
882 ThisType&
slice(Key index, Size size) {
885 const Size maxsize =
size_ - index;
890 }
else if (
size_ > 0) {
907 {
return slice(index1, (index1 < index2 ? index2-index1 : 0)); }
926 { EVO_IMPL_CONTAINER_SWAP(
this, &list, ThisType); }
932 void iterInitMutable()
934 const IterItem* iterFirst(IterKey& key)
const 935 { key = 0;
return data_; }
936 const IterItem* iterNext(IterKey& key)
const {
937 const IterItem* result = NULL;
940 result =
data_ + key;
946 const IterItem* iterNext(Size count, IterKey& key)
const {
947 const IterItem* result = NULL;
949 if ( (key+=count) <
size_ )
950 result =
data_ + key;
956 const IterItem* iterLast(IterKey& key)
const {
957 const IterItem* result = NULL;
960 result =
data_ + key;
964 const IterItem* iterPrev(IterKey& key)
const {
965 const IterItem* result = NULL;
968 result =
data_ + --key;
974 const IterItem* iterPrev(Size count, IterKey& key)
const {
975 const IterItem* result = NULL;
977 if (key > 0 && count <= key)
978 result =
data_ + (key-=count);
984 Size iterCount()
const 986 const IterItem* iterSet(IterKey key)
const {
987 const IterItem* result = NULL;
989 result =
data_ + key;
Iter end() const
Get iterator at end (const).
Definition: sublist.h:642
SubList(const ListBaseType &data, Key index, Size size=ALL)
Copy constructor to reference source data.
Definition: sublist.h:204
bool splitat_setr(Key index)
Split at index and set as right sublist.
Definition: sublist.h:793
bool splitat(Key index, T1 &left) const
Split into left sublist at index.
Definition: sublist.h:743
Size size() const
Get size.
Definition: sublist.h:485
bool contains(const ListBaseType &data) const
Check if contains given data.
Definition: sublist.h:713
IteratorRa< ThisType >::Const Iter
Iterator (const) - IteratorRa.
Definition: sublist.h:166
T Value
Value type (same as Item)
Definition: sublist.h:152
bool starts(const ListBaseType &items) const
Check if this starts with given items.
Definition: sublist.h:590
bool contains(ItemVal item) const
Check whether contains given item.
Definition: sublist.h:692
ValEmpty
Special empty value type, pass as vEMPTY.
Definition: sys.h:1101
ThisType & operator=(const ValEmpty &val)
Assignment operator sets as null.
Definition: sublist.h:318
Key findany(const Item *items, Size count, Key start=0, Key end=END) const
Find first occurrence of any given items with forward search.
Definition: sublist.h:666
Key find(ItemVal item, Key start=0, Key end=END) const
Find first occurrence of item with forward search.
Definition: sublist.h:646
SubList< T, Size > ThisType
This list type.
Definition: sublist.h:156
Key findanyr(const Item *items, Size count, Key start=0, Key end=END) const
Find last occurrence of any given items with reverse search.
Definition: sublist.h:678
bool splitat_setl(Key index)
Split at index and set as left sublist.
Definition: sublist.h:769
bool splitat(Key index, T1 &left, T2 &right) const
Split into left/right sublists at index.
Definition: sublist.h:728
int compare(const ListBaseType &data) const
Comparison.
Definition: sublist.h:546
const Item & operator[](Key index) const
Get item at position.
Definition: sublist.h:511
Size Key
Key type (item index)
Definition: sublist.h:151
Random access iterator.
Definition: iter.h:904
ValNull
Unique null value type and value (vNULL).
Definition: sys.h:1096
SubList(const ListBaseType *data)
Copy constructor to reference source data from pointer.
Definition: sublist.h:223
SubList(ThisType &&src)
Move constructor (C++11).
Definition: sublist.h:269
const Item * first() const
Get first item (const).
Definition: sublist.h:528
SubList(const ThisType &data)
Copy constructor to reference source data.
Definition: sublist.h:180
ThisType & slice(Key index)
Slice beginning items.
Definition: sublist.h:863
bool operator==(const ListBaseType &data) const
Equality operator.
Definition: sublist.h:558
bool contains(const Item *data, Size size) const
Check if contains given data.
Definition: sublist.h:701
SubList()
Default constructor sets as null.
Definition: sublist.h:169
SubList(const ListBaseType &data)
Copy constructor to reference source data.
Definition: sublist.h:191
ThisType & operator=(const ThisType &src)
Assignment operator.
Definition: sublist.h:298
ThisType & set2(const ListBaseType &data, Key index1, Key index2)
Set as reference to subset of source data using start/end positions.
Definition: sublist.h:450
const Item * data() const
Get data pointer.
Definition: sublist.h:502
bool starts(ItemVal item) const
Check if this starts with given item.
Definition: sublist.h:582
void swap(ThisType &list)
Swap with another sublist.
Definition: sublist.h:925
Iter cend() const
Get iterator at end (const).
Definition: sublist.h:623
ThisType & operator=(const ListBaseType *data)
Assignment operator sets as reference to source data from pointer.
Definition: sublist.h:345
ThisType & clear()
Clear by removing all items.
Definition: sublist.h:361
bool ends(const ListBaseType &items) const
Check if this ends with given items.
Definition: sublist.h:602
ThisType & setempty()
Set as empty but not null.
Definition: sublist.h:471
#define EVO_PEMPTY
Special pointer value for empty but not NULL (used in containers).
Definition: type.h:1858
bool shared() const
Get whether shared (false).
Definition: sublist.h:494
Data equality helper.
Definition: container.h:712
ThisType & operator=(const ValNull &val)
Assignment operator sets as null.
Definition: sublist.h:307
TSize Size
List size integer type.
Definition: sublist.h:150
Key findr(ItemVal item, Key start=0, Key end=END) const
Find last occurrence of item with reverse search.
Definition: sublist.h:656
Evo implementation detail: Container iterators.
const ThisType & asconst() const
Explicitly use a const reference to this.
Definition: sublist.h:288
T Item
Item type (same as Value)
Definition: sublist.h:153
ThisType & unshare()
Make data unique – no-op.
Definition: sublist.h:917
static const EndT END
Special integer value for indicating end of items or no item.
Definition: type.h:1846
const Item & item(Key index) const
Get item at position.
Definition: sublist.h:522
static const EndT ALL
Special integer value for indicating all items or all remaining items.
Definition: type.h:1839
bool operator!=(const ListBaseType &data) const
Inequality operator.
Definition: sublist.h:570
Evo container foundation types and macros.
static ulong hash(const T *data, ulong size, ulong seed=0)
Compute hash value from data.
Definition: container.h:899
bool starts(const Item *items, Size size) const
Check if starts with given items.
Definition: sublist.h:586
bool splitat(Key index, ValNull left, T2 &right) const
Split into right sublist at index.
Definition: sublist.h:756
ThisType & operator=(const ListBaseType &data)
Assignment operator sets as reference to source data.
Definition: sublist.h:332
ListBase< T, Size > ListBaseType
List base type for any Evo list
Definition: sublist.h:158
Evo C++ Library namespace.
Definition: alg.h:11
static const EndT NONE
Special integer value for indicating no item or unknown item.
Definition: type.h:1832
ulong hash(ulong seed=0) const
Get data hash value.
Definition: sublist.h:540
DataCopy< T >::PassType ItemVal
Item type as parameter (POD types passed by value, otherwise by const-ref)
Definition: sublist.h:154
Iter cbegin() const
Get iterator at first item (const).
Definition: sublist.h:613
bool ends(ItemVal item) const
Check if this ends with given item.
Definition: sublist.h:594
static int compare(const T *data1, ulong size1, const T *data2, ulong size2)
Compare data.
Definition: container.h:769
ThisType & triml(Size size)
Trim left (beginning) items.
Definition: sublist.h:822
T * data_
Data pointer, NULL if null.
Definition: sys.h:979
AddConst< T >::Type & PassType
Most efficient type for passing as parameter (const-reference or POD value).
Definition: container.h:551
bool splitat_setr(Key index, T1 &left)
Split at index, set as right sublist, and save left sublist.
Definition: sublist.h:806
SubList(const Item *data, Size size)
Constructor to reference data pointer.
Definition: sublist.h:237
Reference and access existing list data.
Definition: sublist.h:145
SubList< T, Size > SubListType
SubList base type
Definition: sublist.h:157
SubList(const Item *data, ValNull v, ItemVal term=0)
Constructor to reference terminated data pointer.
Definition: sublist.h:256
ThisType & slice2(Key index1, Key index2)
Slice to given subset using start/end positions.
Definition: sublist.h:906
ThisType & slice(Key index, Size size)
Slice to given subset.
Definition: sublist.h:882
bool splitat_setl(Key index, T2 &right)
Split at index, set as left sublist, and save right sublist.
Definition: sublist.h:780
TSize size_
Data size as item count, 0 if empty or null.
Definition: sys.h:980
Iter begin() const
Get iterator at first item (const).
Definition: sublist.h:632
ThisType & truncate(Size size)
Truncate to given size.
Definition: sublist.h:845
bool ends(const Item *items, Size size) const
Check if this ends with given items.
Definition: sublist.h:598
ThisType & trimr(Size size)
Trim right (ending) items.
Definition: sublist.h:834
ThisType & operator=(ThisType &&src)
Move assignment operator (C++11).
Definition: sublist.h:277
Base for all Evo list types (used internally).
Definition: sys.h:976
Key iend(Size offset=0) const
Get index from last item using offset.
Definition: sublist.h:536
bool empty() const
Get whether empty.
Definition: sublist.h:481
const Item * last() const
Get last item (const).
Definition: sublist.h:532
#define EVO_PARAM_UNUSED(NAME)
Mark function parameter as unused to suppress "unreferenced parameter" compiler warnings on it...
Definition: sys.h:427
bool null() const
Get whether null.
Definition: sublist.h:477