#define pset_hinsert(pset, key, hash) \
((pset_entry *)_pset_search ((pset), (key), (hash), _pset_hinsert))
-#ifdef STATS
-/**
- * Prints statistics on a set to stdout.
- *
- * @param pset the pset
- */
-void pset_stats (pset *pset);
-#else
-# define pset_stats(s) ((void)0)
-#endif
-
-/* Private */
+/** @privatesection */
typedef enum { _pset_find, _pset_insert, _pset_hinsert } _pset_action;
#define set_hinsert0(set, key, size, hash) \
((set_entry *)_set_search ((set), (key), (size), (hash), _set_hinsert0))
-#ifdef STATS
-/**
- * Prints statistics on a set to stdout.
- *
- * @param set the set
- */
-void set_stats (set *set);
-#else
-# define set_stats(s) ((void)0)
-#endif
-
/* Private */
typedef enum { _set_find, _set_insert, _set_hinsert, _set_hinsert0 } _set_action;
Element *free_list; /**< list of free Elements */
#endif
struct obstack obst; /**< obstack for allocation all data */
-#ifdef STATS
- size_t naccess, ncollision, ndups;
- size_t max_chain_len;
-#endif
};
-#ifdef STATS
-
-void MANGLEP(stats) (SET *table)
-{
- size_t nfree = 0;
-#ifdef PSET
- Element *q = table->free_list;
- while (q) { q = q->chain; ++nfree; }
-#endif
- lc_printf(" accesses collisions keys duplicates longest wasted\n%12zu%12zu%12zu%12zu%12zu%12zu\n",
- table->naccess, table->ncollision, table->nkey, table->ndups, table->max_chain_len, nfree);
-}
-
-static inline void stat_chain_len(SET *table, size_t chain_len)
-{
- table->ncollision += chain_len;
- if (table->max_chain_len < chain_len) table->max_chain_len = chain_len;
-}
-
-# define stat_access(table) (++(table)->naccess)
-# define stat_dup(table) (++(table)->ndups)
-
-#else /* !STATS */
-
-# define stat_chain_len(table, chain_len) ((void)chain_len)
-# define stat_access(table) ((void)0)
-# define stat_dup(table) ((void)0)
-
-#endif /* !STATS */
-
SET *(PMANGLE(new)) (MANGLEP(cmp_fun) cmp, size_t nslots)
{
SET *table = XMALLOC(SET);
table->nseg++;
}
-#ifdef STATS
- table->naccess = table->ncollision = table->ndups = 0;
- table->max_chain_len = 0;
-#endif
return table;
}
int SegmentIndex;
MANGLEP(cmp_fun) cmp = table->cmp;
Segment q;
- size_t chain_len = 0;
assert (table);
assert (key);
- stat_access (table);
/* Find collision chain */
h = Hash (table, hash);
/* Follow collision chain */
while (q && !EQUAL (cmp, q, key, size)) {
q = q->chain;
- ++chain_len;
}
- stat_chain_len(table, chain_len);
-
if (!q && (action != MANGLE(_,_find))) { /* not found, insert */
assert (!table->iter_tail && "insert an element into a set that is iterated");
- if (CurrentSegment[SegmentIndex]) stat_dup (table);
-
#ifdef PSET
if (table->free_list) {
q = table->free_list;
pset_cmp_fun cmp = table->cmp;
Segment *p;
Segment q;
- int chain_len = 0;
assert (table && !table->iter_tail);
- stat_access (table);
/* Find collision chain */
h = Hash (table, hash);
while (!EQUAL (cmp, *p, key, size)) {
p = &(*p)->chain;
assert (*p);
- ++chain_len;
}
- stat_chain_len (table, chain_len);
-
q = *p;
if (q == table->iter_tail) {
pset_Element *iter_tail; /**< non-NULL while iterating over elts */
pset_Element *free_list; /**< list of free Elements */
struct obstack obst; /**< obstack for allocation all data */
-#ifdef STATS
- int naccess, ncollision, ndups;
- int max_chain_len;
-#endif
};
typedef struct set_element {
unsigned iter_i, iter_j;
set_Element *iter_tail; /**< non-NULL while iterating over elts */
struct obstack obst; /**< obstack for allocation all data */
-#ifdef STATS
- int naccess, ncollision, ndups;
- int max_chain_len;
-#endif
};
/**