/** * @returns the first item of the list, or NULL if none. */ void * hash_list_head(const hash_list_t *hl) { struct hash_list_item *item; hash_list_check(hl); item = elist_head(&hl->list); return NULL == item ? NULL : deconstify_pointer(item->key); }
/** * Remove head item from the list. * * @return the data that was stored there. */ void * hash_list_remove_head(hash_list_t *hl) { struct hash_list_item *item; hash_list_check(hl); item = elist_head(&hl->list); return NULL == item ? NULL : hash_list_remove_item(hl, item); }
/** * 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); } }
/** * Remove head item from the list. * * @return the data that was stored there. */ void * hash_list_shift(hash_list_t *hl) { struct hash_list_item *item; hash_list_check(hl); g_assert(1 == hl->refcount); item = elist_head(&hl->list); return NULL == item ? NULL : 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 */ }