libFirm
Generic Hashset

Generic Hashset. More...

Data Structures

struct  set_entry
 The entry of a set, representing an element in the set and its meta-information. More...

Macros

#define set_first(type, set)   ((type*)set_first((set)))
 Returns the first element of a set.
#define set_next(type, set)   ((type*)set_next((set)))
 Returns the next element of a set.
#define foreach_set(set, type, entry)   for (type *entry = set_first(type, set); entry; entry = set_next(type, set))
 Iterates over an set.

Typedefs

typedef struct set set
 The abstract type of a set.
typedef int(* set_cmp_fun )(const void *elt, const void *key, size_t size)
 The type of a set compare function.

Functions

setnew_set (set_cmp_fun func, size_t slots)
 Creates a new set.
void del_set (set *set)
 Deletes a set and all elements of it.
size_t set_count (set *set)
 Returns the number of elements in a set.
void * set_find (set *set, const void *key, size_t size, unsigned hash)
 Searches an element in a set.
void * set_insert (set *set, const void *key, size_t size, unsigned hash)
 Inserts an element into a set.
set_entryset_hinsert (set *set, const void *key, size_t size, unsigned hash)
 Inserts an element into a set and returns its set_entry.
set_entryset_hinsert0 (set *set, const void *key, size_t size, unsigned hash)
 Inserts an element into a set, zero-terminate it and returns its set_entry.
void * set_first (set *set)
 Returns the first element of a set.
void * set_next (set *set)
 Returns the next element of a set.
void set_break (set *set)
 Breaks the iteration of a set.

Detailed Description

Generic Hashset.

Note
This code has been deprecated. Use hashset for new code.

Macro Definition Documentation

#define foreach_set (   set,
  type,
  entry 
)    for (type *entry = set_first(type, set); entry; entry = set_next(type, set))

Iterates over an set.

Parameters
setthe set
typetype of iterator variable
entrythe iterator

Definition at line 225 of file set.h.

#define set_first (   type,
  set 
)    ((type*)set_first((set)))

Returns the first element of a set.

This is a wrapper for set_first(set <em>set); It allows to express the intended type of the set elements (instead of weakly typed void).

Parameters
setthe set to iterate
typetype of the set elements
Returns
a pointer to the element or NULL if the set is empty

Definition at line 184 of file set.h.

#define set_next (   type,
  set 
)    ((type*)set_next((set)))

Returns the next element of a set.

This is a wrapper for set_next(set <em>set); It allows to express the intended type of the set elements (instead of weakly typed void).

Parameters
setthe set to iterate
typetype of the set elements
Returns
a pointer to the next element or NULL if the iteration is finished

Definition at line 207 of file set.h.

Typedef Documentation

typedef struct set set

The abstract type of a set.

This sets stores copies of its elements, so there is no need to store the elements after they were added to a set.

See Also
pset

Definition at line 48 of file set.h.

typedef int(* set_cmp_fun)(const void *elt, const void *key, size_t size)

The type of a set compare function.

Parameters
eltpointer to an element
keypointer to another element
sizesize of the elements
Returns
0 if the elements are identically, non-zero else
Note
Although it is possible to define different meanings of equality of two elements of a set, they can be only equal if their sizes are are equal. This is checked before the compare function is called.

Definition at line 73 of file set.h.

Function Documentation

void del_set ( set set)

Deletes a set and all elements of it.

Parameters
setthe set to delete
set* new_set ( set_cmp_fun  func,
size_t  slots 
)

Creates a new set.

Parameters
funcThe compare function of this set.
slotsInitial number of collision chains. I.e., #slots different keys can be hashed without collisions.
Returns
created set
void set_break ( set set)

Breaks the iteration of a set.

Must be called before the next set_first() call if the iteration was NOT finished.

Parameters
setthe set
size_t set_count ( set set)

Returns the number of elements in a set.

Parameters
setthe set
void* set_find ( set set,
const void *  key,
size_t  size,
unsigned  hash 
)

Searches an element in a set.

Parameters
setthe set to search in
keythe element to is searched
sizethe size of key
hashthe hash value of key
Returns
The address of the found element in the set or NULL if it was not found.
void* set_first ( set set)

Returns the first element of a set.

Parameters
setthe set to iterate
Returns
a pointer to the element or NULL if the set is empty
set_entry* set_hinsert ( set set,
const void *  key,
size_t  size,
unsigned  hash 
)

Inserts an element into a set and returns its set_entry.

Parameters
setthe set to insert in
keya pointer to the element to be inserted. Element is copied!
sizethe size of the element that should be inserted
hashthe hash-value of the element
Returns
a pointer to the set_entry of the inserted element
Note
It is not possible to insert an element more than once. If an element that should be inserted is already in the set, this functions does nothing but returning its set_entry.
set_entry* set_hinsert0 ( set set,
const void *  key,
size_t  size,
unsigned  hash 
)

Inserts an element into a set, zero-terminate it and returns its set_entry.

Parameters
setthe set to insert in
keya pointer to the element to be inserted. Element is copied!
sizethe size of the element that should be inserted
hashthe hash-value of the element
Returns
a pointer to the set_entry of the inserted element
Note
It is not possible to insert on element more than once. If an element that should be inserted is already in the set, this functions does nothing but returning its set_entry.
void* set_insert ( set set,
const void *  key,
size_t  size,
unsigned  hash 
)

Inserts an element into a set.

Parameters
setthe set to insert in
keya pointer to the element to be inserted. Element is copied!
sizethe size of the element that should be inserted
hashthe hash-value of the element
Returns
a pointer to the inserted element
Note
It is not possible to insert one element more than once. If an element that should be inserted is already in the set, this functions does nothing but returning its pointer.
void* set_next ( set set)

Returns the next element of a set.

Parameters
setthe set to iterate
Returns
a pointer to the next element or NULL if the iteration is finished