static inline void hash_list_regression(const hash_list_t * const hl) { g_assert(NULL != hl->ht); g_assert(elist_count(&hl->list) == hikset_count(hl->ht)); g_assert(elist_count(&hl->list) == elist_length(elist_first(&hl->list))); }
/** * @returns the length of the list. */ unsigned hash_list_length(const hash_list_t *hl) { hash_list_check(hl); return elist_count(&hl->list); }
/** * Move entry to the tail of the list. */ void hash_list_moveto_tail(hash_list_t *hl, const void *key) { struct hash_list_item *item; hash_list_check(hl); g_assert(1 == hl->refcount); g_assert(size_is_positive(elist_count(&hl->list))); item = hikset_lookup(hl->ht, key); g_assert(item != NULL); /* * Remove item from list and insert it back at the tail. */ if (elist_last(&hl->list) != &item->lnk) { elist_link_remove(&hl->list, &item->lnk); elist_link_append(&hl->list, &item->lnk); } hl->stamp++; hash_list_regression(hl); }
/** * Clear the list, removing all items. */ void hash_list_clear(hash_list_t *hl) { hash_list_check(hl); g_assert(1 == hl->refcount); while (0 != elist_count(&hl->list)) { struct hash_list_item *item = elist_head(&hl->list); hash_list_remove_item(hl, item); } }
/** * Periodic garbage collecting routine. */ static bool aging_gc(void *obj) { aging_table_t *ag = obj; time_t now = tm_time(); struct aging_value *aval; aging_check(ag); aging_synchronize(ag); g_assert(elist_count(&ag->list) == hikset_count(ag->table)); while (NULL != (aval = elist_head(&ag->list))) { if (delta_time(now, aval->last_insert) <= ag->delay) break; /* List is sorted, oldest items first */ hikset_remove(ag->table, aval->key); aging_free(aval, ag); } aging_return(ag, TRUE); /* Keep calling */ }