#include <stddef.h>
Typedefs | |
typedef struct set_t | set_t |
represents a set. | |
Functions | |
set creating/destroying functions: | |
set_t * | set_new (int, int(const void *, const void *), unsigned(const void *)) |
void | set_free (set_t **) |
destroys a set. | |
data/information retrieving functions: | |
size_t | set_length (set_t *) |
returns the length of a set. | |
int | set_member (set_t *, const void *) |
inspects if a set contains a member. | |
void | set_put (set_t *, const void *) |
puts a member to a set. | |
void * | set_remove (set_t *, const void *) |
removes a member from a set. | |
set handling functions: | |
void | set_map (set_t *, void(const void *, void *), void *) |
void ** | set_toarray (set_t *, void *) |
converts a set to an array. | |
set operation functions: | |
set_t * | set_union (set_t *, set_t *) |
returns a union set of two sets. | |
set_t * | set_inter (set_t *, set_t *) |
returns an intersection of two sets. | |
set_t * | set_minus (set_t *, set_t *) |
returns a difference set of two sets | |
set_t * | set_diff (set_t *, set_t *) |
returns a symmetric difference of two sets. |
Header for Set Library (CDSL).
returns a symmetric difference of two sets.
set_diff() returns a symmetric difference of two sets, that is a set with members only one of two operand sets has. A symmetric difference set is identical to the union set of (s
- t
) and (t
- s
). See set_union() for more detailed explanation commonly applied to the set operation functions.
Possible exceptions: assert_exceptfail, mem_exceptfail
Unchecked errors: foreign data structure given for s
or t
[in] | s | operand of set difference operation |
[in] | t | operand of set difference operation |
void set_free | ( | set_t ** | pset | ) |
destroys a set.
set_free() destroys a set by deallocating the storage for it and set a given pointer to a null pointer. As always, set_free() does not deallocate any storage for members in the set, which must be done by a user.
Possible exceptions: assert_exceptfail
Unchecked errors: pointer to foreign data structure given for pset
[in,out] | pset | pointer to set to destroy |
returns an intersection of two sets.
set_inter() returns an intersection of two sets, that is a set with only members that both have in common. See set_union() for more detailed explanation commonly applied to the set operation functions.
Possible exceptions: assert_exceptfail, mem_exceptfail
Unchecked errors: foreign data structure given for s
or t
[in] | s | operand of set intersection operation |
[in] | t | operand of set intersection operation |
size_t set_length | ( | set_t * | set | ) |
returns the length of a set.
set_length() returns the length of a set which is the number of all members in a set.
Possible exceptions: assert_exceptfail
Unchecked errors: foreign data structure given for set
[in] | set | set whose length returned |
int set_member | ( | set_t * | set, | |
const void * | member | |||
) |
inspects if a set contains a member.
set_member() inspects a set to see if it contains a given member.
Possible exceptions: assert_exceptfail
Unchecked errors: foreign data structure given for set
[in] | set | set to inspect |
[in] | member | member to find in a set |
0 | member not found | |
1 | member found |
returns a difference set of two sets
set_inter() returns a difference of two sets, that is a set with members that t
has but does
not. See set_union() for more detailed explanation commonly applied to the set operation functions.
Possible exceptions: assert_exceptfail, mem_exceptfail
Unchecked errors: foreign data structure given for s
or t
[in] | s | operand of set difference operation |
[in] | t | operand of set difference operation |
s
- t
void set_put | ( | set_t * | set, | |
const void * | member | |||
) |
puts a member to a set.
set_put() inserts a member to a set. If it fails to find a member matched to a given member, it inserts the given member to a set after proper storage allocation. If it finds a matched one, it replaces an existing member with a given one. Even if they compare equal by a user-defined comparison function, they may have different representations. Thus, replacing the old one with the new one makes sense.
Note that a member is a pointer. If members are, say, integers in an application, objects to contain them are necessary to put them into a set.
Possible exceptions: assert_exceptfail, mem_exceptfail
Unchecked errors: foreign data structure given for set
[in,out] | set | set to which member inserted |
[in] | member | member to insert |
void* set_remove | ( | set_t * | set, | |
const void * | member | |||
) |
removes a member from a set.
set_remove() gets rid of a member from a set. Note that set_remove() does not deallocate any storage for the member to remove, which must be done by a user.
Possible exceptions: assert_exceptfail
Unchecked errors: foreign data structure given for set
[in,out] | set | set from whcih member removed |
[in] | member | member to remove |
non-null | previous member | |
NULL | member not found |
void** set_toarray | ( | set_t * | set, | |
void * | end | |||
) |
converts a set to an array.
set_toarray() converts members stored in a set to an array. The last element of the constructed array is assigned by end
, which is a null pointer in most cases. Do not forget deallocate the array when it is unnecessary.
Possible exceptions: assert_exceptfail, mem_exceptfail
Unchecked errors: foreign data structure given for set
As in set_map(), the order in which an array is created for each member is unspecified.
[in] | set | set for which array generated |
[in] | end | end-mark to save in last element of array |
returns a union set of two sets.
set_union() creates a union set of two given sets and returns it. One of those may be a null pointer, in which case a null pointer is considered an empty set. For every operation, its result constitutes a distinct set from its operand sets, which means the set operations always allocate storage for their results even when one of the operands is empty.
Note that the inferface of the Set Library does not assume the concept of a universe, which is the set of all possible members. Thus, a set operation like the complement of a set is not defined and not implemented.
Possible exceptions: assert_exceptfail, mem_exceptfail
Unchecked errors: foreign data structure given for s
or t
[in] | s | operand of set union operation |
[in] | t | operand of set union operation |