charset.h

This interface exports an abstract type that represents sets of characters.
Type
CharSet Defines the abstract type used to represent sets of characters
Functions
newCharSet() Creates an empty set capable of holding characters.
freeCharSet(set) Frees the storage associated with a character set.
size(set) Returns the number of elements in the set.
isEmpty(set) Returns true if the set has no elements.
clear(set) Removes all characters from the set.
clone(set) Creates a copy of the set.
contains(set, ch) Returns true if the character ch is a member of the set.
add(set, ch) Adds the character ch to the set.
addString(set, str) Adds the characters in str to the set.
remove(set, ch) Removes an element from the set.
equals(s1, s2) Returns true if s1 and s2 are equal, which means that they contain the same elements.
isSubset(s1, s2) Returns true if s1 is a subset of s2.
union(s1, s2) Returns a new set consisting of all elements in either s1 or s2.
intersection(s1, s2) Returns a new set consisting of all elements in both s1 and s2.
setDifference(s1, s2) Returns a new set consisting of all elements in s1 that are not elements of s2.

Type detail


typedef struct CharSetCDT *CharSet;
Defines the abstract type used to represent sets of characters

Function detail


CharSet newCharSet();
Creates an empty set capable of holding characters.

Usage:

set = newCharSet();

void freeCharSet(CharSet set);
Frees the storage associated with a character set.

Usage:

freeCharSet(set);

int size(CharSet set);
Returns the number of elements in the set.

Usage:

n = size(set);

bool isEmpty(CharSet set);
Returns true if the set has no elements.

Usage:

if (isEmpty(set)) . . .

void clear(CharSet set);
Removes all characters from the set.

Usage:

clear(set);

CharSet clone(CharSet set);
Creates a copy of the set. The clone function copies only the first level of the structure and does not copy the individual elements.

Usage:

newset = clone(set);

bool contains(CharSet set, char ch);
Returns true if the character ch is a member of the set.

Usage:

if (contains(set, ch)) . . .

void add(CharSet set, char ch);
Adds the character ch to the set.

Usage:

add(set, ch);

void addString(CharSet set, string str);
Adds the characters in str to the set.

Usage:

addString(set, str);

void remove(CharSet set, char ch);
Removes an element from the set.

Usage:

remove(set, ch);

bool equals(CharSet s1, CharSet s2);
Returns true if s1 and s2 are equal, which means that they contain the same elements.

Usage:

if (equals(s1, s2)) . . .

bool isSubset(CharSet s1, CharSet s2);
Returns true if s1 is a subset of s2.

Usage:

if (isSubset(s1, s2)) . . .

CharSet union(CharSet s1, CharSet s2);
Returns a new set consisting of all elements in either s1 or s2.

Usage:

set = union(s1, s2);

CharSet intersection(CharSet s1, CharSet s2);
Returns a new set consisting of all elements in both s1 and s2.

Usage:

set = intersection(s1, s2);

CharSet setDifference(CharSet s1, CharSet s2);
Returns a new set consisting of all elements in s1 that are not elements of s2.

Usage:

set = setDifference(s1, s2);