Nebula
Loading...
Searching...
No Matches
Util::Set< KEYTYPE > Class Template Reference

#include <set.h>

Detailed Description

template<class KEYTYPE>
class Util::Set< KEYTYPE >

A collection of unique values with quick lookup.

Internally implemented as a sorted array.

Adding the same value more than once has no obvious effect.

On insertion performance: Key/value pairs are inserted with the Add() method, which normally calls the Util::Array::InsertSorted() method internally. If many insertions are performed at once, it may be beneficial to call BeginBulkAdd() before, and EndBulkAdd() after adding the key/value pairs. Between BeginBulkAdd() and EndBulkAdd(), the Add() method will just append the new elements to the internal array, and only call Util::Array::Sort() inside EndBulkAdd().

Any methods which require the internal array to be sorted will throw an assertion between BeginBulkAdd() and EndBulkAdd().

Public Member Functions

 Set ()
 default constructor
 
 Set (const Set< KEYTYPE > &rhs)
 copy constructor
 
void operator= (const Set< KEYTYPE > &rhs)
 assignment operator
 
SizeT Size () const
 return number of unique keys
 
void Clear ()
 clear the set
 
bool IsEmpty () const
 return true if empty
 
void Reserve (SizeT numElements)
 reserve space (useful if number of elements is known beforehand)
 
void Add (const KEYTYPE &value)
 add a unique value to set, won't get added twice
 
void Erase (const KEYTYPE &key)
 erase a key and its associated value
 
void EraseAtIndex (IndexT index)
 erase a key at index
 
IndexT FindIndex (const KEYTYPE &key) const
 find index of key pair (InvalidIndex if doesn't exist)
 
bool Contains (const KEYTYPE &key) const
 return true if key exists in the array
 
const KEYTYPE & KeyAtIndex (IndexT index) const
 get a key at given index
 
const Array< KEYTYPE > & KeysAsArray () const
 get all keys as an Util::Array
 
template<class RETURNTYPE >
RETURNTYPE KeysAs () const
 get all keys as (typically) an array
 

Protected Member Functions

void SortIfDirty () const
 make sure the key value pair array is sorted
 

Protected Attributes

Array< KEYTYPE > values
 

Constructor & Destructor Documentation

◆ Set() [1/2]

template<class KEYTYPE >
Util::Set< KEYTYPE >::Set ( )

default constructor

◆ Set() [2/2]

template<class KEYTYPE >
Util::Set< KEYTYPE >::Set ( const Set< KEYTYPE > & rhs)

copy constructor

Member Function Documentation

◆ Add()

template<class KEYTYPE >
void Util::Set< KEYTYPE >::Add ( const KEYTYPE & value)

add a unique value to set, won't get added twice

◆ Clear()

template<class KEYTYPE >
void Util::Set< KEYTYPE >::Clear ( )

clear the set

◆ Contains()

template<class KEYTYPE >
bool Util::Set< KEYTYPE >::Contains ( const KEYTYPE & key) const

return true if key exists in the array

◆ Erase()

template<class KEYTYPE >
void Util::Set< KEYTYPE >::Erase ( const KEYTYPE & key)

erase a key and its associated value

◆ EraseAtIndex()

template<class KEYTYPE >
void Util::Set< KEYTYPE >::EraseAtIndex ( IndexT index)

erase a key at index

◆ FindIndex()

template<class KEYTYPE >
IndexT Util::Set< KEYTYPE >::FindIndex ( const KEYTYPE & key) const

find index of key pair (InvalidIndex if doesn't exist)

◆ IsEmpty()

template<class KEYTYPE >
bool Util::Set< KEYTYPE >::IsEmpty ( ) const

return true if empty

◆ KeyAtIndex()

template<class KEYTYPE >
const KEYTYPE & Util::Set< KEYTYPE >::KeyAtIndex ( IndexT index) const

get a key at given index

◆ KeysAs()

template<class KEYTYPE >
template<class RETURNTYPE >
RETURNTYPE Util::Set< KEYTYPE >::KeysAs ( ) const

get all keys as (typically) an array

◆ KeysAsArray()

template<class KEYTYPE >
const Array< KEYTYPE > & Util::Set< KEYTYPE >::KeysAsArray ( ) const

get all keys as an Util::Array

◆ operator=()

template<class KEYTYPE >
void Util::Set< KEYTYPE >::operator= ( const Set< KEYTYPE > & rhs)

assignment operator

◆ Reserve()

template<class KEYTYPE >
void Util::Set< KEYTYPE >::Reserve ( SizeT numElements)

reserve space (useful if number of elements is known beforehand)

◆ Size()

template<class KEYTYPE >
SizeT Util::Set< KEYTYPE >::Size ( ) const

return number of unique keys

◆ SortIfDirty()

template<class KEYTYPE >
void Util::Set< KEYTYPE >::SortIfDirty ( ) const
protected

make sure the key value pair array is sorted

Member Data Documentation

◆ values

template<class KEYTYPE >
Array<KEYTYPE> Util::Set< KEYTYPE >::values
protected

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