Evo C++ Library v0.5.1
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Set< TKey, TSize > Class Template Referenceabstract

#include <evo/set.h>

Inheritance diagram for Set< TKey, TSize >:
Inheritance graph
[legend]

Detailed Description

template<class TKey, class TSize = SizeT>
class evo::Set< TKey, TSize >

Associative container with unique values for fast lookup.

Template Parameters
TKeySet value and value type
TSizeSize type to use for size values (must be unsigned integer) – default: SizeT
Features
Iterators

Caution: Modifying or resizing a set will shift or invalidate existing iterators using it.

Read Access
Modifiers
Comparison Object

Sets that use a hash/comparison type will have these additional methods (not included in this interface), where T is the hash/compare type used:

See SetList or SetHash for example.

Ordered Sets

Ordered sets will have these additional methods (not included in this interface):

See SetList for example.

List Sets

List sets will have these additional methods (not included in this interface):

See SetList for example.

Example

See implementation types for examples: SetList, SetHash

Public Types

typedef void EvoContainerType
 
typedef TKey Item
 Item type (same as Value) More...
 
typedef IteratorBi< ThisType >::Const Iter
 Iterator (const) - IteratorBi. More...
 
typedef IteratorBi< ThisTypeIterM
 Iterator (mutable) - IteratorBi. More...
 
typedef TKey Key
 Key type (same as Value) More...
 
typedef Set< TKey, TSize > SetBaseType
 Set base type More...
 
typedef TSize Size
 Size type for size values (must be unsigned integer) – default: SizeT. More...
 
typedef Set< TKey, TSize > ThisType
 This type. More...
 
typedef TKey Value
 Value type. More...
 

Public Member Functions

virtual ~Set ()
 Destructor. More...
 
virtual Valueadd (const Value &value, bool update=false)=0
 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 SetBaseTypeasconst () 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...
 
virtual Size capacity () const =0
 Get set capacity. More...
 
virtual SetBaseTypecapacity (Size size)=0
 Set capacity for set (modifier). More...
 
virtual SetBaseTypecapacitymin (Size min)=0
 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...
 
virtual SetBaseTypeclear ()=0
 Clear by removing all items. More...
 
virtual SetBaseTypecompact ()
 Reduce capacity to fit current size (modifier). More...
 
virtual bool contains (const Value &value) const =0
 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...
 
virtual Valueget (const Value &value, bool *created=NULL)=0
 Get value, create if needed (mutable). More...
 
Iter iter (const Value &value) const
 Find (lookup) iterator for given value (const). More...
 
IterM iterM (const Value &value)
 Find (lookup) iterator for given value (mutable). More...
 
virtual bool null () const =0
 Get whether set is null. More...
 
bool operator!= (const SetBaseType &set) const
 Inequality operator. More...
 
SetBaseTypeoperator= (const SetBaseType &src)
 Assignment operator. More...
 
bool operator== (const SetBaseType &set) const
 Equality operator. More...
 
virtual bool ordered () const =0
 Get whether set is ordered. More...
 
virtual bool remove (const Value &value)=0
 Find and remove given value. More...
 
virtual bool remove (IterM &iter, IteratorDir dir=iterNONE)=0
 Remove item using given iterator. More...
 
SetBaseTypereserve (Size size)
 Reserve space for new items. More...
 
virtual SetBaseTypeset ()=0
 Set as null and empty. More...
 
virtual SetBaseTypeset (const SetBaseType &src)=0
 Set as copy of given set. More...
 
virtual SetBaseTypesetempty ()=0
 Set as empty but not null. More...
 
virtual bool shared () const =0
 Get whether shared. More...
 
Size size () const
 Get set size (number of items). More...
 
virtual SetBaseTypeunshare ()=0
 Make data unique by allocating new buffer, if needed (modifier). More...
 

Protected Member Functions

 Set ()
 Constructor. More...
 
 Set (const ThisType &)=delete
 Copy constructor (disabled). More...
 
virtual const Valuegetiter (IterKey &iterkey, const Value &value) const =0
 Used by base class to get data to initialize iterator. More...
 

Protected Attributes

Size size_
 Set size (number of items, automatically updated by concrete set members) More...
 

Member Typedef Documentation

◆ EvoContainerType

typedef void EvoContainerType

◆ Item

typedef TKey Item

Item type (same as Value)

◆ Iter

typedef IteratorBi<ThisType>::Const Iter

Iterator (const) - IteratorBi.

◆ IterM

Iterator (mutable) - IteratorBi.

◆ Key

typedef TKey Key

Key type (same as Value)

◆ SetBaseType

typedef Set<TKey,TSize> SetBaseType

Set base type

◆ Size

typedef TSize Size

Size type for size values (must be unsigned integer) – default: SizeT.

◆ ThisType

typedef Set<TKey,TSize> ThisType

This type.

◆ Value

typedef TKey Value

Value type.

Constructor & Destructor Documentation

◆ Set() [1/2]

Set ( )
inlineprotected

Constructor.

Used by derived types.

◆ Set() [2/2]

Set ( const ThisType )
protecteddelete

Copy constructor (disabled).

◆ ~Set()

virtual ~Set ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ add()

virtual Value& add ( const Value value,
bool  update = false 
)
pure virtual

Add or update using given item.

Parameters
valueValue to add (copied)
updateWhether to update existing item, true to overwrite existing item – use when items that compare as equal can have diff metadata
Returns
Reference to added item

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, and SetHash< TKey, THash, TSize >.

◆ addfrom()

Size addfrom ( const T &  items,
bool  update = false 
)
inline

Add items from given list or set.

Template Parameters
TContainer type to add from – can be Set, List, Array, or similar
Parameters
itemsList to add items from
updateWhether to update existing item, true to overwrite existing items – use when items that compare as equal can have diff metadata
Returns
Number of new items added

◆ addsplit()

Size addsplit ( const T &  str,
char  delim = ',' 
)
inline

Split delimited string into set items.

  • This parses/tokenizes str and adds each item to set, using convert() for conversion to set item type
  • Set value types must be convertible from String via convert()
  • See joinset() to join set back into string
Template Parameters
TString type to parse – inferred from str parameter
Parameters
strString to parse
delimValue delimiter to use
Returns
Number of items added to set

◆ asconst()

const SetBaseType& asconst ( ) const
inline

Explicitly use a const reference to this.

  • This is useful to force using this as const without casting
Returns
This

◆ begin() [1/2]

IterM begin ( )
inline

Get iterator at first item (mutable).

  • This allows compatibility with range-based for loops and other libraries, otherwise use container Iter directly
  • cbegin() is more efficient, since this effectively calls unshare() to make items mutable
Returns
Iterator at first item, or at end position if empty
See also
IterM, end(), cbegin(), cend()

◆ begin() [2/2]

Iter begin ( ) const
inline

Get iterator at first item (const).

  • This allows compatibility with range-based for loops and other libraries, otherwise use container Iter directly
Returns
Iterator at first item, or at end position if empty
See also
end() const, cbegin()

◆ capacity() [1/2]

virtual Size capacity ( ) const
pure virtual

Get set capacity.

Returns
Current capacity

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, and SetHash< TKey, THash, TSize >.

◆ capacity() [2/2]

virtual SetBaseType& capacity ( Size  size)
pure virtual

Set capacity for set (modifier).

  • This is just a suggestion – some sets may ignore it
Parameters
sizeNew capacity
Returns
This

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, and SetHash< TKey, THash, TSize >.

◆ capacitymin()

virtual SetBaseType& capacitymin ( Size  min)
pure virtual

Set capacity to at least given minimum for set (modifier).

  • This is just a suggestion – some sets may ignore it
Parameters
minMinimum capacity
Returns
This

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, and SetHash< TKey, THash, TSize >.

◆ cbegin()

Iter cbegin ( ) const
inline

Get iterator at first item (const).

  • This allows compatibility with range-based for loops and other libraries, otherwise use container Iter directly
Returns
Iterator at first item, or at end position if empty
See also
Iter, cend(), begin(), end()

◆ cend()

Iter cend ( ) const
inline

Get iterator at end (const).

  • This allows compatibility with range-based for loops and other libraries, otherwise use container Iter directly
  • This really just creates an empty iterator
Returns
Iterator at end position
See also
Iter, cbegin(), begin(), end()

◆ clear()

virtual SetBaseType& clear ( )
pure virtual

Clear by removing all items.

  • Does not set as null – null status is unchanged
Returns
This

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, and SetHash< TKey, THash, TSize >.

◆ compact()

virtual SetBaseType& compact ( )
inlinevirtual

Reduce capacity to fit current size (modifier).

  • Call to save memory when done adding items
  • This is just a suggestion – some implementations may ignore it
Returns
This

Reimplemented in SetList< TKey, TCompare, TSize >, and SetList< String >.

◆ contains()

virtual bool contains ( const Value value) const
pure virtual

Get whether the set contains the given value.

Parameters
valueValue to look for
Returns
Whether value was found

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, and SetHash< TKey, THash, TSize >.

◆ empty()

bool empty ( ) const
inline

Get whether set is empty (size is 0).

Returns
Whether empty

◆ end() [1/2]

IterM end ( )
inline

Get iterator at end.

  • This allows compatibility with range-based for loops and other libraries, otherwise use container Iter directly
  • This really just creates an empty iterator
Returns
Iterator at end position
See also
IterM, begin(), cbegin(), cend()

◆ end() [2/2]

Iter end ( ) const
inline

Get iterator at end (const).

  • This allows compatibility with range-based for loops and other libraries, otherwise use container Iter directly
  • This really just creates an empty iterator
Returns
Iterator at end position
See also
begin() const, cend()

◆ get()

virtual Value& get ( const Value value,
bool *  created = NULL 
)
pure virtual

Get value, create if needed (mutable).

  • Existing value is returned as-is
  • New value is created via copy constructor
Parameters
valueValue to use, copied if new value is created
createdStores whether new item was created, if not NULL
Returns
Reference to new value

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, and SetHash< TKey, THash, TSize >.

◆ getiter()

virtual const Value* getiter ( IterKey &  iterkey,
const Value value 
) const
protectedpure virtual

Used by base class to get data to initialize iterator.

Parameters
iterkeySet to iterator data, if item found
valueValue to find
Returns
Value pointer, NULL if not found

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, and SetHash< TKey, THash, TSize >.

◆ iter()

Iter iter ( const Value value) const
inline

Find (lookup) iterator for given value (const).

Parameters
valueValue to find
Returns
Iterator, at end position if value not found

◆ iterM()

IterM iterM ( const Value value)
inline

Find (lookup) iterator for given value (mutable).

  • Caution: Results are undefined if value is modified in a way that changes it's ordered position in set
Parameters
valueValue to find
Returns
Iterator, at end position if value not found

◆ null()

virtual bool null ( ) const
pure virtual

Get whether set is null.

Returns
Whether null

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, and SetHash< TKey, THash, TSize >.

◆ operator!=()

bool operator!= ( const SetBaseType set) const
inline

Inequality operator.

Parameters
setSet to compare to
Returns
Whether sets are not equal (don't have same items)

◆ operator=()

SetBaseType& operator= ( const SetBaseType src)
inline

Assignment operator.

Parameters
srcSource to copy
Returns
This

◆ operator==()

bool operator== ( const SetBaseType set) const
inline

Equality operator.

Parameters
setSet to compare to
Returns
Whether sets are equal (have same items)

◆ ordered()

virtual bool ordered ( ) const
pure virtual

Get whether set is ordered.

  • Ordered sets keep items in order by value so iteration order is predictable

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, and SetHash< TKey, THash, TSize >.

◆ remove() [1/2]

virtual bool remove ( const Value value)
pure virtual

Find and remove given value.

Parameters
valueValue to use
Returns
Whether value was removed, false if not found

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, and SetHash< TKey, THash, TSize >.

◆ remove() [2/2]

virtual bool remove ( IterM iter,
IteratorDir  dir = iterNONE 
)
pure virtual

Remove item using given iterator.

  • This will move the iterator to the next item according to dir, or end position if no more
  • Caution: Removing an item may shift other iterators on same set, in an unpredictable way
Parameters
iterIterator position
dirDirection to move iterator to next item, iterNONE for end position
Returns
Whether item was removed, false if iterator at end position

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, SetList< TKey, TCompare, TSize >, SetList< String >, SetHash< TKey, THash, TSize >, and SetHash< TKey, THash, TSize >.

◆ reserve()

SetBaseType& reserve ( Size  size)
inline

Reserve space for new items.

  • For best performance, call this before adding multiple values
  • This calls capacitymin() with current size + size to reserve space
  • This is just a suggestion – some implementations may ignore it
Parameters
sizeSize to reserve
Returns
This

◆ set() [1/2]

virtual SetBaseType& set ( )
pure virtual

Set as null and empty.

Returns
This

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, and SetHash< TKey, THash, TSize >.

◆ set() [2/2]

virtual SetBaseType& set ( const SetBaseType src)
pure virtual

Set as copy of given set.

  • This clears all items in current set.
Parameters
srcSource items
Returns
This

Implemented in SetList< TKey, TCompare, TSize >, and SetList< String >.

◆ setempty()

virtual SetBaseType& setempty ( )
pure virtual

Set as empty but not null.

Returns
This

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, and SetHash< TKey, THash, TSize >.

◆ shared()

virtual bool shared ( ) const
pure virtual

Get whether shared.

  • Data is shared when referencing external data or buffer is allocated and shared (reference count > 1)
Returns
Whether shared

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, and SetHash< TKey, THash, TSize >.

◆ size()

Size size ( ) const
inline

Get set size (number of items).

Returns
Set size

◆ unshare()

virtual SetBaseType& unshare ( )
pure virtual

Make data unique by allocating new buffer, if needed (modifier).

  • Use reserve() instead to reserve additional space while unsharing
  • Use to make buffer unique (not shared) and writable (when not empty)
  • This is called automatically by mutable/modifier methods
  • This does nothing if empty or not shared
Returns
This

Implemented in SetList< TKey, TCompare, TSize >, SetList< String >, and SetHash< TKey, THash, TSize >.

Member Data Documentation

◆ size_

Size size_
protected

Set size (number of items, automatically updated by concrete set members)


The documentation for this class was generated from the following file: