A set is a data structure which contains a "collection" of elements stored in no specific order, which can only store each value once. Unlike other collection data structures, typically sets are only added to and then used to test for Element within the set. The set data structure can be thought of as an implementation of a finite set. Sets usually define the following operations:
Additionally, some set implementations may provide operations for the following:
template <class T>
class Set {
public:
Set();
// Add an element to the set
void add(const T& element);
// Remove an element from the set
void remove(const T& element);
// Check if the set contains an element
bool contains(const T& element) const;
}
A common implementation of a set is using a hash table, where each element is stored in an array based on the hash value of the element. This allows for average-case