Reference Guide: Sets

This section is a reference guide to classes/interfaces built by API on top of Set abstract data type:

Advantages and disadvantages of each data structure as Set implementation are described in great detail by this section. Please review it carefully in order to decide which solution suits your business needs!

To see how can above classes be iterated, please review iterators section. To see a real life example how can above classes be used, please have a look at unit tests.

Set

Forward iterator prototype for Set abstract data type, hiding data structure on top

Signature

template <typename T> class Set

Methods

Method Signature Description
~Set virtual ~Set () Deletes elements inside from heap memory
clear virtual void clear () = 0 Clears Set of all elements
contains virtual bool contains (const T& value) const = 0 Checks if Set contains value
isEmpty virtual bool isEmpty () const = 0 Checks if Set is empty of values
size virtual const std::size_t& size () const = 0 Gets number of elements in set
add virtual void add (const T& value) = 0 Adds value to set
remove virtual void remove (const T& value) = 0 Removes value from set
find T* find (const T& value) Gets address of set element pointed by value
begin virtual SetIterator<T>* begin () = 0 Returns an iterator to the first element of set
end virtual SetIterator<T>* end () = 0 Returns an iterator to the element following last element of set

HashSet

Class that implements Hash Table data structure on top of Set abstract data type

Signature

template <typename T, int (*compare)(const T&,const T&) = comparator<T>, std::size_t (*hash)(const T&) = hash<T>> class HashSet : public Set<T>

Additional Methods

Method Signature Description
HashSet HashSet () Constructs a Hash Table of unknown initial size
HashSet HashSet (const std::size_t& reservedSize) Constructs a Hash Table of known size

LinkedHashSet

Class that implements Linked Hash Table data structure on top of Set abstract data type

Signature

template <typename T, int (*compare)(const T&,const T&) = comparator<T>, std::size_t (*hash)(const T&) = hash<T>> class LinkedHashSet : public Set<T>

Additional Methods

Method Signature Description
LinkedHashSet LinkedHashSet () Constructs a Linked Hash Table of unknown initial size
LinkedHashSet LinkedHashSet (const std::size_t& reservedSize) Constructs a Linked Hash Table of known size
sort void sort (bool (*comparator) (const T&, const T&)) Sorts elements inside by comparator

TreeSet

Class that implements Red Black Tree data structure on top of Set abstract data type

Signature

template <typename T, int (*compare)(const T&,const T&) = comparator<T>> class TreeSet : public Set<T>

Additional Methods

Method Signature Description
TreeSet TreeSet () Constructs a Red Black Tree of unknown initial size

Share