libFirm

(Hash)sets containing pointers. More...

Data Structures

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

Macros

#define pset_insert_ptr(set, key)   pset_insert(set, key, hash_ptr(key))
 Inserts into pointer set with default hash function. More...
 
#define pset_hinsert_ptr(set, key)   pset_hinsert(set, key, hash_ptr(key))
 Inserts into pointer set with default hash function and return entry. More...
 
#define pset_remove_ptr(set, key)   pset_remove(set, key, hash_ptr(key))
 Removes pointer from pointer set with default hash function. More...
 
#define pset_find_ptr(set, key)   pset_find(set, key, hash_ptr(key))
 Finds pointer in pointer set with default hash function. More...
 
#define pset_new_ptr(slots)   new_pset(pset_default_ptr_cmp, slots)
 Creates new pointer set with default compare function. More...
 
#define pset_new_ptr_default()   pset_new_ptr(64)
 Creates new pointer set with default compare function and default size. More...
 
#define pset_first(type, pset)   ((type*)pset_first((pset)))
 Returns the first element of a pset. More...
 
#define pset_next(type, pset)   ((type*)pset_next((pset)))
 Returns the next element of a pset. More...
 
#define foreach_pset(pset, type, entry)   for (type *entry = pset_first(type, pset); entry; entry = pset_next(type, pset))
 Iterates over a pset. More...
 

Typedefs

typedef struct pset pset
 The abstract type of a pset (Set of pointers). More...
 
typedef int(* pset_cmp_fun) (void const *elt, void const *key)
 The type of a set compare function. More...
 

Functions

int pset_default_ptr_cmp (void const *x, void const *y)
 The default comparison function for pointers. More...
 
psetnew_pset (pset_cmp_fun func, size_t slots)
 Creates a new pset. More...
 
void del_pset (pset *pset)
 Deletes a pset. More...
 
size_t pset_count (pset const *pset)
 Returns the number of elements in a pset. More...
 
void * pset_find (pset *pset, void const *key, unsigned hash)
 Searches an element pointer in a pset. More...
 
void * pset_insert (pset *pset, void const *key, unsigned hash)
 Inserts an element pointer into a pset. More...
 
pset_entrypset_hinsert (pset *pset, void const *key, unsigned hash)
 Inserts an element pointer into a pset and returns its pset_entry. More...
 
void * pset_remove (pset *pset, void const *key, unsigned hash)
 Removes an element from a pset. More...
 
void * pset_first (pset *pset)
 Returns the first element of a pset. More...
 
void * pset_next (pset *pset)
 Returns the next element of a pset. More...
 
void pset_break (pset *pset)
 Breaks the iteration of a set. More...
 
void pset_insert_pset_ptr (pset *target, pset *src)
 Inserts all elements of the pointer set src into the set target (union). More...
 

Detailed Description

(Hash)sets containing pointers.

Note
This code has been deprecated. Use pset_new or cpset for new code.

Data Structure Documentation

◆ pset_entry

struct pset_entry

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

Definition at line 62 of file pset.h.

Data Fields
void * dptr pointer to element data
unsigned hash hash value of element

Macro Definition Documentation

◆ foreach_pset

#define foreach_pset (   pset,
  type,
  entry 
)    for (type *entry = pset_first(type, pset); entry; entry = pset_next(type, pset))

Iterates over a pset.

Parameters
psetthe pset
typetype of iterator variable
entrythe iterator

Definition at line 227 of file pset.h.

◆ pset_find_ptr

#define pset_find_ptr (   set,
  key 
)    pset_find(set, key, hash_ptr(key))

Finds pointer in pointer set with default hash function.

Definition at line 54 of file pset.h.

◆ pset_first

#define pset_first (   type,
  pset 
)    ((type*)pset_first((pset)))

Returns the first element of a pset.

This is a wrapper for pset_first(set); It allows to express the intended type of the set elements (instead of weakly typed void*).

Parameters
typedestination type of the pointers in the set
psetthe pset to iterate
Returns
a pointer to the element or NULL if the set is empty

Definition at line 186 of file pset.h.

◆ pset_hinsert_ptr

#define pset_hinsert_ptr (   set,
  key 
)    pset_hinsert(set, key, hash_ptr(key))

Inserts into pointer set with default hash function and return entry.

Definition at line 50 of file pset.h.

◆ pset_insert_ptr

#define pset_insert_ptr (   set,
  key 
)    pset_insert(set, key, hash_ptr(key))

Inserts into pointer set with default hash function.

Definition at line 48 of file pset.h.

◆ pset_new_ptr

#define pset_new_ptr (   slots)    new_pset(pset_default_ptr_cmp, slots)

Creates new pointer set with default compare function.

Definition at line 56 of file pset.h.

◆ pset_new_ptr_default

#define pset_new_ptr_default ( )    pset_new_ptr(64)

Creates new pointer set with default compare function and default size.

Definition at line 58 of file pset.h.

◆ pset_next

#define pset_next (   type,
  pset 
)    ((type*)pset_next((pset)))

Returns the next element of a pset.

This is a wrapper for pset_next(set); It allows to express the intended type of the set elements (instead of weakly typed void*).

Parameters
typedestination type of the pointers in the set
psetthe pset to iterate
Returns
a pointer to the next element or NULL if the iteration is finished

Definition at line 209 of file pset.h.

◆ pset_remove_ptr

#define pset_remove_ptr (   set,
  key 
)    pset_remove(set, key, hash_ptr(key))

Removes pointer from pointer set with default hash function.

Definition at line 52 of file pset.h.

Typedef Documentation

◆ pset

typedef struct pset pset

The abstract type of a pset (Set of pointers).

This kind of sets stores only pointer to elements, the elements itself must be stored somewhere else.

See also
set

Definition at line 45 of file pset.h.

◆ pset_cmp_fun

typedef int(* pset_cmp_fun) (void const *elt, void const *key)

The type of a set compare function.

Parameters
eltpointer to an element
keypointer to another element
Returns
0 if the elements are identically, non-zero else

Definition at line 76 of file pset.h.

Function Documentation

◆ del_pset()

void del_pset ( pset pset)

Deletes a pset.

Parameters
psetthe pset
Note
This does NOT delete the elements of this pset, just its pointers!

◆ new_pset()

pset* new_pset ( pset_cmp_fun  func,
size_t  slots 
)

Creates a new pset.

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

◆ pset_break()

void pset_break ( pset pset)

Breaks the iteration of a set.

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

Parameters
psetthe pset

◆ pset_count()

size_t pset_count ( pset const *  pset)

Returns the number of elements in a pset.

Parameters
psetthe pset

◆ pset_default_ptr_cmp()

int pset_default_ptr_cmp ( void const *  x,
void const *  y 
)

The default comparison function for pointers.

Parameters
xA pointer.
yA pointer.
Returns
0 if x and y are equal. Some value != 0 otherwise.

◆ pset_find()

void* pset_find ( pset pset,
void const *  key,
unsigned  hash 
)

Searches an element pointer in a pset.

Parameters
psetthe pset to search in
keythe element to search
hashthe hash value of key
Returns
the pointer of the found element in the pset or NULL if it was not found

◆ pset_first()

void* pset_first ( pset pset)

Returns the first element of a pset.

Parameters
psetthe pset to iterate
Returns
a pointer to the element or NULL if the set is empty

◆ pset_hinsert()

pset_entry* pset_hinsert ( pset pset,
void const *  key,
unsigned  hash 
)

Inserts an element pointer into a pset and returns its pset_entry.

Parameters
psetthe pset to insert in
keya pointer to the element to be inserted
hashthe hash-value of the element
Returns
a pointer to the pset_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 pset, this functions does nothing but returning its pset_entry.

◆ pset_insert()

void* pset_insert ( pset pset,
void const *  key,
unsigned  hash 
)

Inserts an element pointer into a pset.

Parameters
psetthe pset to insert in
keya pointer to the element to be inserted
hashthe hash-value of the element
Returns
a pointer to 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 already existing set_entry.

◆ pset_insert_pset_ptr()

void pset_insert_pset_ptr ( pset target,
pset src 
)

Inserts all elements of the pointer set src into the set target (union).

Parameters
targetthe target set, will contain the union
srca set, will not be changed

◆ pset_next()

void* pset_next ( pset pset)

Returns the next element of a pset.

Parameters
psetthe pset to iterate
Returns
a pointer to the next element or NULL if the iteration is finished

◆ pset_remove()

void* pset_remove ( pset pset,
void const *  key,
unsigned  hash 
)

Removes an element from a pset.

Parameters
psetthe pset to delete in
keya pointer to the element to be deleted
hashthe hash-value of the element
Returns
the pointer to the removed element
Remarks
The current implementation did not allow to remove non-existing elements. @@ so, does it do now? Further, it is allowed to remove elements during an iteration including the current one.