libFirm 1.20
Set (custom Compare)

A pointer set with user-definable compare function. More...

Typedefs

typedef int(* cpset_cmp_function )(const void *p1, const void *p2)
 The type of a cpset compare function.
typedef unsigned(* cpset_hash_function )(const void *obj)
 The type of a cpset hash function.
typedef struct cpset_t cpset_t
 a pointer set with custom compare function
typedef struct cpset_iterator_t cpset_iterator_t
 iterator over a pointer set with custom compare function

Functions

void cpset_init (cpset_t *cpset, cpset_hash_function hash_function, cpset_cmp_function cmp_function)
 Initializes a cpset.
void cpset_init_size (cpset_t *cpset, cpset_hash_function hash_function, cpset_cmp_function cmp_function, size_t expected_elements)
 Initializes a cpset.
void cpset_destroy (cpset_t *cpset)
 Destroys a cpset and frees the memory allocated for hashtable.
void * cpset_insert (cpset_t *cpset, void *obj)
 Inserts an element into a cpset.
void cpset_remove (cpset_t *cpset, const void *obj)
 Removes an element from a cpset.
void * cpset_find (const cpset_t *cpset, const void *obj)
 Tests whether a cpset contains a pointer.
size_t cpset_size (const cpset_t *cpset)
 Returns the number of pointers contained in the cpset.
void cpset_iterator_init (cpset_iterator_t *iterator, const cpset_t *cpset)
 Initializes a cpset iterator.
void * cpset_iterator_next (cpset_iterator_t *iterator)
 Advances the iterator and returns the current element or NULL if all elements in the cpset have been processed.
void cpset_remove_iterator (cpset_t *cpset, const cpset_iterator_t *iterator)
 Removed the element the iterator currently points to.

Detailed Description

A pointer set with user-definable compare function.


Typedef Documentation

typedef int(* cpset_cmp_function)(const void *p1, const void *p2)

The type of a cpset compare function.

Parameters:
p1pointer to an element
p2pointer to another element
Returns:
1 if the elements are identically, zero else

Definition at line 46 of file cpset.h.

typedef unsigned(* cpset_hash_function)(const void *obj)

The type of a cpset hash function.

Definition at line 51 of file cpset.h.

iterator over a pointer set with custom compare function

See also:
cpset_t

Definition at line 73 of file cpset.h.

typedef struct cpset_t cpset_t

a pointer set with custom compare function

Definition at line 70 of file cpset.h.


Function Documentation

void cpset_destroy ( cpset_t cpset)

Destroys a cpset and frees the memory allocated for hashtable.

The memory of the cpset itself is not freed.

Parameters:
cpsetPointer to the cpset
void* cpset_find ( const cpset_t cpset,
const void *  obj 
)

Tests whether a cpset contains a pointer.

Parameters:
cpsetPointer to the cpset
objThe pointer to find
Returns:
An equivalent object to obj or NULL
void cpset_init ( cpset_t cpset,
cpset_hash_function  hash_function,
cpset_cmp_function  cmp_function 
)

Initializes a cpset.

Parameters:
cpsetPointer to allocated space for the cpset
hash_functionThe hash function to use
cmp_functionThe compare function to use
void cpset_init_size ( cpset_t cpset,
cpset_hash_function  hash_function,
cpset_cmp_function  cmp_function,
size_t  expected_elements 
)

Initializes a cpset.

Parameters:
cpsetPointer to allocated space for the cpset
hash_functionThe hash function to use
cmp_functionThe compare function to use
expected_elementsNumber of elements expected in the cpset (roughly)
void* cpset_insert ( cpset_t cpset,
void *  obj 
)

Inserts an element into a cpset.

Parameters:
cpsetPointer to the cpset
objElement to insert into the cpset
Returns:
The element itself or a pointer to an existing element
void cpset_iterator_init ( cpset_iterator_t iterator,
const cpset_t cpset 
)

Initializes a cpset iterator.

Sets the iterator before the first element in the cpset.

Parameters:
iteratorPointer to already allocated iterator memory
cpsetPointer to the cpset
void* cpset_iterator_next ( cpset_iterator_t iterator)

Advances the iterator and returns the current element or NULL if all elements in the cpset have been processed.

Attention:
It is not allowed to use cpset_insert or cpset_remove while iterating over a cpset.
Parameters:
iteratorPointer to the cpset iterator.
Returns:
Next element in the cpset or NULL
void cpset_remove ( cpset_t cpset,
const void *  obj 
)

Removes an element from a cpset.

Does nothing if the cpset doesn't contain the element.

Parameters:
cpsetPointer to the cpset
objPointer to remove from the cpset
void cpset_remove_iterator ( cpset_t cpset,
const cpset_iterator_t iterator 
)

Removed the element the iterator currently points to.

Parameters:
cpsetPointer to the cpset
iteratorPointer to the cpset iterator.
size_t cpset_size ( const cpset_t cpset)

Returns the number of pointers contained in the cpset.

Parameters:
cpsetPointer to the cpset
Returns:
Number of pointers contained in the cpset