Clarisse 4.0 SP5b SDK  4.0.0.0.5.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Static Public Member Functions | Friends | List of all members
CoreSet< T > Class Template Reference
Inheritance diagram for CoreSet< T >:
CoreBaseObject CoreBaseType

Public Member Functions

 CoreSet ()
 Empty constructor.
 
 CoreSet (const CoreSet< T > &set)
 Copy constructor.
 
 CoreSet (CoreSet< T > &&set)
 Move constructor.
 
 CoreSet (std::initializer_list< T > list)
 
CoreSet< T > & operator= (const CoreSet< T > &set)
 Assignment operator.
 
CoreSet< T > & operator= (CoreSet< T > &&set)
 Move assignment operator.
 
const unsigned int & get_count () const
 Get the number of items in the set.
 
unsigned int get_index (const T &item) const
 Returns the index of the item, CORE_INVALID_INDEX if not found.
 
bool exists (const T &item) const
 Returns true if item exists.
 
bool exists (const T &item, unsigned int &index) const
 
bool is_empty () const
 Returns true if the set is empty.
 
bool is_included (const CoreSet< T > &set) const
 Returns true if all incoming set objects exist in objects list.
 
const CoreBasicArray< T > & get_items () const
 Get a const ref to the items.
 
const T & get_item (unsigned int index) const
 Get an item by index (const version)
 
T & get_item (unsigned int index)
 Get an item by index.
 
const T & back () const
 Get the last item (const version)
 
T & back ()
 Get the last item.
 
const T & operator[] (unsigned int index) const
 Get an item by index (const version)
 
T & operator[] (unsigned int index)
 Get an item by index.
 
void get_array (CoreArray< T > &array) const
 Fills incoming array with set objects.
 
void get_list (CoreList< T > &list) const
 Fills incoming list with set objects.
 
void get_vector (CoreVector< T > &vector) const
 Fills incoming vector with set objects.
 
CoreArray< T > to_array (void) const
 
bool add (const T &item)
 
bool add (const T &item, unsigned int &index)
 
bool add (T &&item)
 
bool add (T &&item, unsigned int &index)
 
void remove (unsigned int index)
 Removes an item by index.
 
bool remove_item (const T &item)
 
void remove_set (const CoreSet< T > &set)
 
void remove_all (void)
 Removes everything.
 
bool toggle (const T &item)
 
void unite (const CoreSet< T > &set)
 Adds all inexisting incoming set objects.
 
void intersect (const CoreSet< T > &set)
 Keep only the objects existing in both set.
 
bool operator== (const CoreSet< T > &set) const
 Equality operator.
 
bool operator!= (const CoreSet< T > &set) const
 Inequality operator.
 
CoreBasicArrayIterator< T > begin (void)
 Get an iterator on the first item.
 
CoreBasicArrayIterator< T > begin (void) const
 Get an iterator on the first item.
 
CoreBasicArrayIterator< T > end (void)
 Get an iterator on the container's end (1 item past the last one)
 
CoreBasicArrayIterator< T > end (void) const
 Get an iterator on the container's end (1 item past the last one)
 
size_t get_memory_size (void) const
 Get the size in bytes used by this instance.
 
template<>
constexpr unsigned int get_linear_search_threshold (void)
 
template<>
constexpr unsigned int get_linear_search_threshold (void)
 
template<>
constexpr unsigned int get_linear_search_threshold (void)
 
template<>
constexpr unsigned int get_linear_search_threshold (void)
 
template<>
constexpr unsigned int get_linear_search_threshold (void)
 
template<>
constexpr unsigned int get_linear_search_threshold (void)
 
- Public Member Functions inherited from CoreBaseObject
bool is_kindof (const CoreBaseObject &object) const
 
CoreString get_class_info_name () const
 
CoreString get_class_interface () const
 
const unsigned long & get_class_info_id () const
 
bool is_kindof (const CoreClassInfo &cinfo) const
 
virtual const CoreClassInfoget_class_info () const
 
bool operator== (const CoreBaseObject &obj) const
 
template<class T >
T * cast ()
 
template<class T >
const T * cast () const
 
- Public Member Functions inherited from CoreBaseType
bool is_kindof (const CoreClassInfo &cinfo) const
 
bool operator== (const CoreBaseType &obj) const
 

Static Public Member Functions

static constexpr unsigned int get_linear_search_threshold (void)
 
- Static Public Member Functions inherited from CoreBaseObject
static const CoreClassInfoclass_info ()
 
static bool ___class_destructor__ (void *instance, const bool &is_array)
 
template<class T >
static T * cast (CoreBaseObject *object)
 
template<class T >
static const T * cast (const CoreBaseObject *object)
 
- Static Public Member Functions inherited from CoreBaseType
static bool ___class_destructor__ (void *instance, const bool &is_array)
 
static const CoreClassInfoclass_info ()
 

Friends

class CoreSetTests
 

Detailed Description

template<class T>
class CoreSet< T >

Collection of unique items with fast iteration capabilities. The items are stored in a CoreVector for fast/contiguous access and iteration, and a CoreHashTable is used to ensure unicity.

Note
Even though the set uses a hash indirection table to quickly check if an item exists or not, if the set is small enough, it might be faster to just iterate on all items and test for equality. The threshold under which a linear search is faster than computing the hash and using the indirection table varies a lot depending on the type of item. For strings for instance, it's quite low. But for most data that fits in 64 bits, it's a lot higher.

The threshold is configurable by specializing the static get_linear_search_threshold.

Template Parameters
TThe type of items stored in the set.

Constructor & Destructor Documentation

template<class T>
CoreSet< T >::CoreSet ( std::initializer_list< T >  list)
inline

Initializer list constructor. Allows syntax like this: CoreSet<CoreString> set{ "hello", "world" };

Member Function Documentation

template<class T>
bool CoreSet< T >::add ( const T &  item)

Adds a new item to the set.

Parameters
[in]itemto be added.
Returns
true if item has been added, false otherwise ( = it already exists)
template<class T>
bool CoreSet< T >::add ( const T &  item,
unsigned int &  index 
)

Adds new item to the set.

Parameters
[in]itemto be added.
[out]indexof the added (or existing item)
Returns
true if item has been added, false otherwise ( = it already exists).
template<class T>
bool CoreSet< T >::add ( T &&  item)

Moves a new item to the set

Parameters
[in]itemto be moved.
Returns
true if item has been added, false otherwise ( = it already exists)
template<class T>
bool CoreSet< T >::add ( T &&  item,
unsigned int &  index 
)

Moves new item to the set.

Parameters
[in]itemto be moved.
[out]indexof the added (or existing item)
Returns
true if item has been added, false otherwise ( = it already exists).
template<class T>
bool CoreSet< T >::exists ( const T &  item,
unsigned int &  index 
) const
inline

Returns true if item exists, and set index to its index

Parameters
[in]itemto look for.
[out]indexof the found item, unchanged if item not found.
template<class T >
constexpr unsigned int CoreSet< T >::get_linear_search_threshold ( void  )
static

This static helper can be used to customize the behavior of the exists methods of CoreSet when its LINEAR_SEARCH_THRESHOLD template parameter is left at its default value.

You can specialize this method for various types as you see fit. Usually the more expensive it is to invoke the type's equlity operator the less this limit should be, so for CoreString we provide another specialization for instance.

template<class T>
bool CoreSet< T >::remove_item ( const T &  item)

Removes an item

Parameters
[in]itemto be removed.
template<class T>
void CoreSet< T >::remove_set ( const CoreSet< T > &  set)

Removes all items existing in incoming set

Parameters
[in]setwith items to be removed in ourself.
template<class T >
CoreArray< T > CoreSet< T >::to_array ( void  ) const
inline

Returns an array containing this set's items. This will create a copy of the items.

template<class T>
bool CoreSet< T >::toggle ( const T &  item)

Toggles the existance of incoming item. Removes it if it exists, adds it if not.

Parameters
[in]itemto toggle.