template<class TKey, class TCompare = Compare<TKey>, class TSize = SizeT>
class evo::SetList< TKey, TCompare, TSize >
Set implemented as an ordered sequential array/list.
- Template Parameters
-
TKey | Set key type |
TCompare | Comparison type to use |
TSize | Size type to use for size values (must be unsigned integer) – default: SizeT |
- Features
- Similar to STL set, with an implementation similar to STL vector
- Values are stored sequentially in memory as a dynamic array – random access with item() uses constant time
- Values are always unique (no duplicates)
- This uses binary search – lookups are
O(log n)
, inserts are O(n + log n)
since values must be shifted to make room
- This uses List internally while keeping items ordered
- No memory allocated by new empty set
- Preallocates extra memory when buffer grows
- Sharing makes copying efficient
- See List features
C++11:
- Range-based for loop – see STL Compatibility
SetList<int> list;
for (auto num : list.asconst()) {
}
- Initialization lists
SetList<int> list = {3, 1, 2};
SetList<String> strlist = {"foo", "bar"};
- Move semantics
- Comparison
You can leave the default comparison type (Compare) or specify an alternative.
See: Primitives & Containers
- Iterators
Caution: Modifying or resizing a set will shift or invalidate existing iterators using it.
- Constructors
- Read Access
- Modifiers
- Examples
Example using a set of numbers
int main() {
set.add(10);
set.addsplit("30,40");
bool has10 = set.contains(10);
bool has50 = set.contains(50);
return 0;
}
Output:
Example using descending (reverse) order
int main() {
MySet set;
set.add(10);
set.add(30);
return 0;
}
Output:
Example using string set:
int main() {
while (iter_end && iter_end->starts(PREFIX))
++iter_end;
return 0;
}
Output:
|
| SetList () |
| Default constructor. More...
|
|
| SetList (const SetBaseType &src) |
| Copy constructor. More...
|
|
| SetList (const ThisType &src) |
| Copy constructor. More...
|
|
| SetList (std::initializer_list< Value > init) |
| Sequence constructor (C++11). More...
|
|
| SetList (ThisType &&src) |
| Move constructor (C++11). More...
|
|
| ~SetList () |
| Destructor. More...
|
|
Value & | add (const Value &item, bool update=false) |
| Add or update using given item. More...
|
|
template<class T > |
Size | addfrom (const T &items, bool update=false) |
| Add items from given list or set. More...
|
|
template<class T > |
Size | addsplit (const T &str, char delim=',') |
| Split delimited string into set items. More...
|
|
const ThisType & | asconst () const |
| Explicitly use a const reference to this. More...
|
|
IterM | begin () |
| Get iterator at first item (mutable). More...
|
|
Iter | begin () const |
| Get iterator at first item (const). More...
|
|
Size | capacity () const |
| Get set capacity. More...
|
|
ThisType & | capacity (Size size) |
| Set capacity for set (modifier). More...
|
|
ThisType & | capacitymin (Size min) |
| Set capacity to at least given minimum for set (modifier). More...
|
|
Iter | cbegin () const |
| Get iterator at first item (const). More...
|
|
Iter | cend () const |
| Get iterator at end (const). More...
|
|
ThisType & | clear () |
| Clear by removing all items. More...
|
|
ThisType & | compact () |
| Reduce capacity to fit current size (modifier). More...
|
|
bool | contains (const Value &value) const |
| Get whether the set contains the given value. More...
|
|
bool | empty () const |
| Get whether set is empty (size is 0). More...
|
|
IterM | end () |
| Get iterator at end. More...
|
|
Iter | end () const |
| Get iterator at end (const). More...
|
|
Value & | get (const Value &value, bool *created=NULL) |
| Get value, create if needed (mutable). More...
|
|
const Compare & | get_compare () const |
| Get comparison object being used for comparisons (const). More...
|
|
Compare & | get_compare () |
| Get comparison object being used for comparisons. More...
|
|
const Value & | item (Size index) const |
| Get item value at position (const). More...
|
|
Iter | iter (const Value &value) const |
| Find (lookup) iterator for given value (const). More...
|
|
Iter | iter_lower (const Value &value) const |
| Find first value greater or equal to given value (lower bound) (const). More...
|
|
IterM | iter_lowerM (const Value &value) |
| Find first value greater or equal to given value (lower bound). More...
|
|
Iter | iter_upper (const Value &value) const |
| Find first value greater than given value (upper bound) (const). More...
|
|
IterM | iter_upperM (const Value &value) |
| Find first value greater than given value (upper bound). More...
|
|
IterM | iterM (const Value &value) |
| Find (lookup) iterator for given value (mutable). More...
|
|
bool | null () const |
| Get whether set is null. More...
|
|
bool | operator!= (const SetBaseType &set) const |
| Inequality operator. More...
|
|
bool | operator!= (const ThisType &set) const |
| Inequality operator. More...
|
|
ThisType & | operator= (ThisType &&src) |
| Move assignment operator (C++11). More...
|
|
ThisType & | operator= (const SetBaseType &src) |
| Assignment operator. More...
|
|
ThisType & | operator= (const ThisType &src) |
| Assignment operator. More...
|
|
bool | operator== (const SetBaseType &set) const |
| Equality operator. More...
|
|
bool | operator== (const ThisType &set) const |
| Equality operator. More...
|
|
bool | ordered () const |
| Get whether set is ordered. More...
|
|
bool | remove (const Value &value) |
| Find and remove given value. More...
|
|
Size | remove (const Value &value, Size count) |
| Find and remove value and following values. More...
|
|
bool | remove (typename SetBaseType::IterM &iter, IteratorDir dir=iterNONE) |
| Remove item using given iterator. More...
|
|
bool | remove (IterM &iter, IteratorDir dir=iterNONE) |
| Remove item using given iterator. More...
|
|
Size | remove_range (IterM &start, Size count) |
| Remove range of values using iterator (mutable). More...
|
|
Size | remove_range (IterM &start, IterM &end) |
| Remove range of values using iterators (mutable). More...
|
|
Size | removeat (Size index, Size count=1) |
| Remove value(s) at given position/index (mutable). More...
|
|
ThisType & | reserve (Size size) |
| Reserve space for new items. More...
|
|
ThisType & | set () |
| Set as null and empty. More...
|
|
ThisType & | set (const SetBaseType &src) |
| Set as copy of given set. More...
|
|
ThisType & | set (const ThisType &src) |
| Set as copy of given set. More...
|
|
ThisType & | setempty () |
| Set as empty but not null. More...
|
|
bool | shared () const |
| Get whether shared. More...
|
|
Size | size () const |
| Get set size (number of items). More...
|
|
ThisType & | unshare () |
| Make data unique by allocating new buffer, if needed (modifier). More...
|
|