ATLAS Offline Software
Classes | Macros | Typedefs | Functions
set.h File Reference

Set of values. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _SetIterator
 Definition of a SetIterator. More...
 

Macros

#define SET_NULL   ((void *) 0)
 A null SetValue. More...
 

Typedefs

typedef struct _Set Set
 Represents a set of values. More...
 
typedef struct _SetIterator SetIterator
 An object used to iterate over a set. More...
 
typedef struct _SetEntry SetEntry
 Internal structure representing an entry in the set. More...
 
typedef void * SetValue
 A value stored in a Set. More...
 
typedef unsigned long(* SetHashFunc) (SetValue value)
 Hash function. More...
 
typedef int(* SetEqualFunc) (SetValue value1, SetValue value2)
 Equality function. More...
 
typedef void(* SetFreeFunc) (SetValue value)
 Function used to free values stored in a set. More...
 

Functions

Setset_new (SetHashFunc hash_func, SetEqualFunc equal_func)
 Create a new set. More...
 
void set_free (Set *set)
 Destroy a set. More...
 
void set_register_free_function (Set *set, SetFreeFunc free_func)
 Register a function to be called when values are removed from the set. More...
 
int set_insert (Set *set, SetValue data)
 Add a value to a set. More...
 
int set_remove (Set *set, SetValue data)
 Remove a value from a set. More...
 
int set_query (Set *set, SetValue data)
 Query if a particular value is in a set. More...
 
int set_num_entries (Set *set)
 Retrieve the number of entries in a set. More...
 
SetValueset_to_array (Set *set)
 Create an array containing all entries in a set. More...
 
Setset_union (Set *set1, Set *set2)
 Perform a union of two sets. More...
 
Setset_intersection (Set *set1, Set *set2)
 Perform an intersection of two sets. More...
 
void set_iterate (Set *set, SetIterator *iter)
 Initialise a SetIterator structure to iterate over the values in a set. More...
 
int set_iter_has_more (SetIterator *iterator)
 Determine if there are more values in the set to iterate over. More...
 
SetValue set_iter_next (SetIterator *iterator)
 Using a set iterator, retrieve the next value from the set. More...
 

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_iterate to initialise a SetIterator structure, with set_iter_next and set_iter_has_more to read each value in turn.

Two sets can be combined (union) using set_union, while the intersection of two sets can be generated using set_intersection.

Definition in file set.h.

Macro Definition Documentation

◆ SET_NULL

#define SET_NULL   ((void *) 0)

A null SetValue.

Definition at line 96 of file set.h.

Typedef Documentation

◆ Set

typedef struct _Set Set

Represents a set of values.

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

Definition at line 1 of file set.h.

◆ SetEntry

typedef struct _SetEntry SetEntry

Internal structure representing an entry in the set.

Definition at line 1 of file set.h.

◆ SetEqualFunc

typedef int(* SetEqualFunc) (SetValue value1, SetValue value2)

Equality function.

Compares two values to determine if they are equivalent.

Definition at line 108 of file set.h.

◆ SetFreeFunc

typedef void(* SetFreeFunc) (SetValue value)

Function used to free values stored in a set.

See set_register_free_function.

Definition at line 115 of file set.h.

◆ SetHashFunc

typedef unsigned long(* SetHashFunc) (SetValue value)

Hash function.

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

Definition at line 101 of file set.h.

◆ SetIterator

typedef struct _SetIterator SetIterator

An object used to iterate over a set.

See also
set_iterate

Definition at line 1 of file set.h.

◆ SetValue

typedef void* SetValue

A value stored in a Set.

Definition at line 79 of file set.h.

Function Documentation

◆ set_free()

void set_free ( Set set)

Destroy a set.

Parameters
setThe set to destroy.

◆ set_insert()

int set_insert ( Set set,
SetValue  data 
)

Add a value to a set.

Parameters
setThe set.
dataThe value 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, or if it was not possible to allocate memory for the new entry.

◆ set_intersection()

Set* set_intersection ( Set set1,
Set set2 
)

Perform an intersection of two sets.

Parameters
set1The first set.
set2The second set.
Returns
A new set containing all values which are in both set, or NULL if it was not possible to allocate memory for the new set.

◆ set_iter_has_more()

int set_iter_has_more ( SetIterator iterator)

Determine if there are more values in the set to iterate over.

Parameters
iteratorThe set iterator object.
Returns
Zero if there are no more values in the set to iterate over, non-zero if there are more values to be read.

◆ set_iter_next()

SetValue set_iter_next ( SetIterator iterator)

Using a set iterator, retrieve the next value from the set.

Parameters
iteratorThe set iterator.
Returns
The next value from the set, or SET_NULL if no more values are available.

◆ set_iterate()

void set_iterate ( Set set,
SetIterator iter 
)

Initialise a SetIterator structure to iterate over the values in a set.

Parameters
setThe set to iterate over.
iterPointer to an iterator structure to initialise.

◆ set_new()

Set* set_new ( SetHashFunc  hash_func,
SetEqualFunc  equal_func 
)

Create a new set.

Parameters
hash_funcHash function used on values in the set.
equal_funcCompares two values in the set to determine if they are equal.
Returns
A new set, or NULL if it was not possible to allocate the memory for the set.

◆ set_num_entries()

int set_num_entries ( Set set)

Retrieve the number of entries in a set.

Parameters
setThe set.
Returns
A count of the number of entries in the set.

◆ set_query()

int set_query ( Set set,
SetValue  data 
)

Query if a particular value is in a set.

Parameters
setThe set.
dataThe value to query for.
Returns
Zero if the value is not in the set, non-zero if the value is in the set.

◆ set_register_free_function()

void set_register_free_function ( Set set,
SetFreeFunc  free_func 
)

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

Parameters
setThe set.
free_funcFunction to call when values are removed from the set.

◆ set_remove()

int set_remove ( Set set,
SetValue  data 
)

Remove a value from a set.

Parameters
setThe set.
dataThe value to remove from the set.
Returns
Non-zero (true) if the value was found and removed from the set, zero (false) if the value was not found in the set.

◆ set_to_array()

SetValue* set_to_array ( Set set)

Create an array containing all entries in a set.

Parameters
setThe set.
Returns
An array containing all entries in the set, or NULL if it was not possible to allocate memory for the array.

◆ set_union()

Set* set_union ( Set set1,
Set set2 
)

Perform a union of two sets.


Parameters
set1The first set.
set2The second set.
Returns
A new set containing all values which are in the first or second sets, or NULL if it was not possible to allocate memory for the new set.