libFirm 1.20
Pointer Set

(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...

Defines

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

Typedefs

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

Functions

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

Detailed Description

(Hash)sets containing pointers.

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

Define Documentation

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

Iterates oven an pset.

Parameters:
psetthe pset
typetype of iterator variable
entrythe iterator

Definition at line 218 of file pset.h.

#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 68 of file pset.h.

#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 64 of file pset.h.

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

Inserts into pointer set with default hash function.

Definition at line 62 of file pset.h.

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

Creates new pointer set with default compare function.

Definition at line 70 of file pset.h.

#define pset_new_ptr_default ( )    pset_new_ptr(64)

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

Definition at line 72 of file pset.h.

#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 66 of file pset.h.


Typedef Documentation

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 59 of file pset.h.

typedef int(* pset_cmp_fun)(const void *elt, const void *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 89 of file pset.h.


Function Documentation

void del_pset ( pset pset)

Deletes a pset.

Parameters:
psetthe pset
Note:
This does NOT delete the elements of this pset, just its pointers!
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
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
size_t pset_count ( pset pset)

Returns the number of elements in a pset.

Parameters:
psetthe pset
int pset_default_ptr_cmp ( const void *  x,
const void *  y 
)

The default comparison function for pointers.

Parameters:
xA pointer.
yA pointer.
Returns:
0 if x and y are equal. Some value != 0 otherwise.
void* pset_find ( pset pset,
const void *  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
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_entry* pset_hinsert ( pset pset,
const void *  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.
void* pset_insert ( pset pset,
const void *  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.
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
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
void* pset_remove ( pset pset,
const void *  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.