![]() |
set.h
Type | |
Defines the abstract type used to represent sets. | |
Functions | |
Creates an empty set of values of the specified base type. | |
Creates a new set of values with the specified base type expressed as a string. | |
Frees the storage associated with a set. | |
Returns the number of elements in the set. | |
Returns true if the set has no elements. | |
Removes all elements from the set. | |
Creates a copy of the set. | |
Returns true if the specified value is a member of the set. | |
Adds the specified value to the set. | |
Removes the specified value from the set. | |
Returns true if s1 and s2 are equal, which means that they contain the same elements. | |
Returns true if s1 is a subset of s2 . | |
Returns a new set consisting of all elements in either s1 or s2 . | |
Returns a new set consisting of all elements in both s1 and s2 . | |
Returns a new set consisting of all elements in s1 that are not elements of s2 . | |
Sets the comparison function for elements in the set. | |
Returns the comparison function for elements in the set. |
typedef struct SetCDT *Set;
type
parameter must be an explicit type name like
int
or string
.
Usage:
set = newSet(type);
Set newSetFromType(string baseType);
Usage:
set = newSetFromType(baseType);
void freeSet(Set set);
Usage:
freeSet(set);
int size(Set set);
Usage:
n = size(set);
bool isEmpty(Set set);
true
if the set has no elements.
Usage:
if (isEmpty(set)) . . .
void clear(Set set);
Usage:
clear(set);
Set clone(Set set);
clone
function copies
only the first level of the structure and does not copy the individual
elements.
Usage:
newset = clone(set);
bool contains(Set set, ...);
true
if the specified value is a member of the set.
Usage:
if (contains(set, value)) . . .
void add(Set set, ...);
Usage:
add(set, value);
void remove(Set set, ...);
Usage:
remove(set, value);
bool equals(Set s1, Set s2);
true
if s1
and s2
are equal, which means that they contain the same elements.
Usage:
if (equals(s1, s2)) . . .
bool isSubset(Set s1, Set s2);
true
if s1
is a subset of
s2
.
Usage:
if (isSubset(s1, s2)) . . .
Set union(Set s1, Set s2);
s1
or s2
.
Usage:
set = union(s1, s2);
Set intersection(Set s1, Set s2);
s1
and s2
.
Usage:
set = intersection(s1, s2);
Set setDifference(Set s1, Set s2);
s1
that are not elements of s2
.
Usage:
set = setDifference(s1, s2);
void setCompareFn(Set set, CompareFn cmpFn);
Usage:
setCompareFn(set, cmpFn);
CompareFn getCompareFn(Set set);
Usage:
cmpFn = getCompareFn(set);