ASL
Loading...
Searching...
No Matches
Set< T > Class Template Reference

Detailed Description

template<class T>
class asl::Set< T >

A set is a container of unique elements in any order.

The type of items must have a corresponding global hash() function.

numbers << 3 << -4 << 1 << 3; // number 3 (repeated) will only appear once in the set
if(numbers.contains(10)) -> false (10 is not in the set)
foreach(int x, numbers)
{
cout << x << endl;
}
An Array is a contiguous and resizable array of any type of elements.
Definition Array.h:77
bool contains(const T &x) const
Returns true if the array contains an element equal to x.
Definition Array.h:324
Set in(const Set &s) const
Returns the items from this set which also belong to another set.
Definition Set.h:156

You can perform operations between sets:

Set<int> even = {0, 2, 4, 6, 8, 10};
Set<int> powers = {1, 2, 4, 8, 16, 32};
Set<int> evenOrPower = even + powers; // -> {0, 1, 2, 4, 6, 8, 10, 16, 32}
Set<int> evenNotPower = even - powers; // -> {0, 6, 10}
if(even.contains(powers)) // false, not all powers numbers are in the even set.
if(even.containsAny(powers)) // true, even numbers have (some) numbers from the powers set.

#include <asl/Set.h>

Inherits ASL_SET_MAP< T, int >.

Public Member Functions

Array< Tarray () const
 Returns the set items as an array.
 
Setoperator<< (const T &x)
 Adds an item to the set.
 
Setoperator<< (const Set &s)
 Adds all items in set s into this set.
 
bool operator== (const Set &s) const
 Returns true if both sets have the same items.
 
bool operator!= (const Set &s) const
 Returns true if both sets don't have the same items.
 
bool contains (const T &x) const
 Checks if this set contains a given item.
 
bool contains (const Set &s) const
 Checks if this set contains all items from another set.
 
bool containsAny (const Set &s) const
 Checks if this set contains at least one item from another set.
 
Set notIn (const Set &s) const
 Returns the items from this set which do not belong to another set.
 
Set in (const Set &s) const
 Returns the items from this set which also belong to another set.
 
Set operator& (const Set &s) const
 Returns the items from this set which also belong to another set (intersection)
 
Set operator- (const Set &s) const
 Returns the items from this set which do not belong to another set (subtraction)
 
Set operator+ (const Set &s) const
 Returns all items from this and another set (union)
 
bool empty () const
 Returns true if the set is empty.
 

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