Main Page | Data Structures | File List | Data Fields | Globals

set.h File Reference

Set of values. More...


Typedefs

typedef _Set Set
 Represents a set of data.
typedef unsigned long(* SetHashFunc )(void *data)
 Hash function.
typedef int(* SetEqualFunc )(void *data1, void *data2)
 Equality function.
typedef void *(* SetCopyFunc )(void *data)
 Copy function.
typedef void(* SetIterator )(void *data, void *user_data)
 Set iterator.
typedef void(* SetFreeFunc )(void *data)
 Function used to free values stored in a set.

Functions

Setset_new (SetHashFunc hash_func, SetEqualFunc equal_func)
 Create a new set.
void set_free (Set *set)
 Destroy a set.
void set_register_free_function (Set *set, SetFreeFunc free_func)
 Register a function to be called when values are removed from the set.
int set_insert (Set *set, void *data)
 Add a value to a set.
int set_remove (Set *set, void *data)
 Remove a value from a set.
int set_query (Set *set, void *data)
 Query if a particular value is in a set.
void set_foreach (Set *set, SetIterator callback, void *user_data)
 Iterate over all values in a set.
int set_num_entries (Set *set)
 Retrieve the number of entries in a set.
void ** set_to_array (Set *set)
 Create an array containing all entries in a set.
Setset_union (Set *set1, Set *set2, SetCopyFunc copy_func)
 Perform a union of two sets.
Setset_intersection (Set *set1, Set *set2, SetCopyFunc copy_func)
 Perform an intersection of two sets.


Detailed Description

Set of values.

A set stores a collection of values. Each value can only exist once in the set.

To create a new set, use set_new. To destroy a set, use set_free.

To add a value to a set, use set_insert. To remove a value from a set, use set_remove.

To find the number of entries in a set, use set_num_entries.

To query if a particular value is in a set, use set_query.

To iterate over all values in a set, use set_foreach.


Typedef Documentation

typedef struct _Set Set
 

Represents a set of data.

Created using the set_new function and destroyed using the set_free function.

See also:
set_new

set_free

typedef void*(* SetCopyFunc)(void *data)
 

Copy function.

Given a pointer to some data, return a copy of it. Used by set_intersection and set_union.

typedef int(* SetEqualFunc)(void *data1, void *data2)
 

Equality function.

Compares two values to determine if they are equivalent.

typedef void(* SetFreeFunc)(void *data)
 

Function used to free values stored in a set.

See set_register_free_function.

typedef unsigned long(* SetHashFunc)(void *data)
 

Hash function.

Generates a hash key for data to be stored in a set.

typedef void(* SetIterator)(void *data, void *user_data)
 

Set iterator.

Callback function used to iterate over values in a set.


Function Documentation

void set_foreach Set set,
SetIterator  callback,
void *  user_data
 

Iterate over all values in a set.

Parameters:
set The set.
callback Callback function to be invoked for each value.
user_data Extra data to be passed to the callback function.

void set_free Set set  ) 
 

Destroy a set.

Parameters:
set The set to destroy.

int set_insert Set set,
void *  data
 

Add a value to a set.

Parameters:
set The set.
data The data to add to the set .
Returns:
Non-zero (true) if the value was added to the set, zero (false) if it already exists in the set.

Set* set_intersection Set set1,
Set set2,
SetCopyFunc  copy_func
 

Perform an intersection of two sets.

Parameters:
set1 The first set.
set2 The second set.
copy_func Pointer to a function to use to copy data. When values are inserted into the new set, they are first copied using the copy function. If NULL is passed, no copying is performed and the reference from the first set is added.
Returns:
A new set containing all values which are in both sets.

Set* set_new SetHashFunc  hash_func,
SetEqualFunc  equal_func
 

Create a new set.

Parameters:
hash_func Hash function used on data in the set .
equal_func Compares two values in the set to determine if they are equal.
Returns:
A new set.

int set_num_entries Set set  ) 
 

Retrieve the number of entries in a set.

Parameters:
set The set.
Returns:
A count of the number of entries in the set.

int set_query Set set,
void *  data
 

Query if a particular value is in a set.

Parameters:
set The set.
data The data to query for.
Returns:
Zero if the data is not in the set, non-zero if the data is in the set.

void set_register_free_function Set set,
SetFreeFunc  free_func
 

Register a function to be called when values are removed from the set.

Parameters:
set The set.
free_func Function to call when values are removed from the set.

int set_remove Set set,
void *  data
 

Remove a value from a set.

Parameters:
set The set.
data The data to remove from the set.
Returns:
Non-zero (true) if the data was found and removed from the set, zero (false) if the data was not found in the set.

void** set_to_array Set set  ) 
 

Create an array containing all entries in a set.

Parameters:
set The set.
Returns:
An array containing all entries in the set.

Set* set_union Set set1,
Set set2,
SetCopyFunc  copy_func
 

Perform a union of two sets.

Parameters:
set1 The first set.
set2 The second set.
copy_func Pointer to a function to use to copy data. When values are inserted into the new set, they are first copied using the copy function. If NULL is passed, no copying is performed and the reference from the first set is added.
Returns:
A new set containing all values which are in the first or second sets.


Generated on Mon Jan 30 18:56:23 2006 for C Algorithms by  doxygen 1.4.4