libFirm

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. More...
 
#define set_next(type, set)   ((type*)set_next((set)))
 Returns the next element of a set. More...
 
#define foreach_set(set, type, entry)   for (type *entry = set_first(type, set); entry; entry = set_next(type, set))
 Iterates over an set. More...
 

Typedefs

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

Functions

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

Detailed Description

Generic Hashset.

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

Data Structure Documentation

struct set_entry

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

Definition at line 37 of file set.h.

Data Fields
int dptr[1] the element itself, data copied in must not need more alignment than this
unsigned hash the hash value of the element
size_t size the size of the element

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 212 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); 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 171 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); 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 194 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 34 of file set.h.

typedef int(* set_cmp_fun) (void const *elt, void const *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 59 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 const *  set)

Returns the number of elements in a set.

Parameters
setthe set
void* set_find ( set set,
void const *  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,
void const *  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,
void const *  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,
void const *  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