#include <stddef.h>
#include "hashptr.h"
+#include "iterator.h"
-/*
- * Define some convenience macros using the predefined hash function.
+/**
+ * The default comparison function for pointers.
+ * @param x A pointer.
+ * @param y A pointer.
+ * @return 0 if @p x and @p y are equal. Some value != 0 otherwise.
*/
-#define pset_insert_ptr(set,key) pset_insert(set, key, HASH_PTR(key))
-#define pset_hinsert_ptr(set,key) pset_hinsert(set, key, HASH_PTR(key))
-#define pset_remove_ptr(set,key) pset_remove(set, key, HASH_PTR(key))
-#define pset_find_ptr(set,key) pset_find(set, key, HASH_PTR(key))
+int pset_default_ptr_cmp(const void *x, const void *y);
/**
* The abstract type of a pset (Set of pointers).
*/
typedef struct pset pset;
+/*
+ * Define some convenience macros using the predefined hash function.
+ */
+#define pset_insert_ptr(set,key) pset_insert(set, key, HASH_PTR(key))
+#define pset_hinsert_ptr(set,key) pset_hinsert(set, key, HASH_PTR(key))
+#define pset_remove_ptr(set,key) pset_remove(set, key, HASH_PTR(key))
+#define pset_find_ptr(set,key) pset_find(set, key, HASH_PTR(key))
+#define pset_new_ptr(slots) new_pset(pset_default_ptr_cmp, slots)
+#define pset_new_ptr_default() pset_new_ptr(64)
+
/** The entry of a pset, representing an element pointer in the set and it's meta-information */
typedef struct {
unsigned hash;
* @param hash the hash value of key
*
* @return
- * the pointer of the found element in the pset of NULL if it was not found
+ * the pointer of the found element in the pset or NULL if it was not found
*/
void *pset_find (pset *pset, const void *key, unsigned hash);
* @return a pointer to the inserted element
*
* @note
- * It is not possible to insert on element more than once. If a element
+ * 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.
* @return a pointer to the pset_entry of the inserted element
*
* @note
- * It is not possible to insert on element more than once. If a element
+ * 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.
*/
/**
* Removes an element from a pset.
*
- * @param pset the pset to insert in
- * @param key a pointer to the element to be inserted
+ * @param pset the pset to delete in
+ * @param key a pointer to the element to be deleted
* @param hash the hash-value of the element
*
* @return
*
* @remark
* 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.
*/
*/
void pset_break (pset *pset);
+/**
+ * Inserts all elements of the pointer set src into
+ * the set target (union).
+ *
+ * @param target the target set, will contain the union
+ * @param src a set, will not be changed
+ */
+void pset_insert_pset_ptr(pset *target, pset *src);
+
#define new_pset(cmp, slots) (PSET_TRACE (new_pset) ((cmp), (slots)))
#define pset_find(pset, key, hash) \
_pset_search ((pset), (key), (hash), _pset_find)