int hashtable_itor_prev(hashtable_itor *itor) { unsigned slot; hash_node *node; ASSERT(itor != NULL); if ((node = itor->node) == NULL) return hashtable_itor_last(itor); slot = itor->slot; node = node->prev; if (node) { itor->node = node; return 1; } while (slot > 0) if ((node = itor->table->table[--slot]) != NULL) { for (; node->next; node = node->next) /* void */; break; } itor->node = node; itor->slot = slot; RETVALID(itor); }
bool hashtable_itor_prev(hashtable_itor* itor) { ASSERT(itor != NULL); if (!itor->node) return hashtable_itor_last(itor); itor->node = itor->node->prev; if (itor->node) return true; unsigned slot = itor->slot; while (slot > 0) { hash_node* node = itor->table->table[--slot]; if (node) { while (node->next) node = node->next; itor->node = node; itor->slot = slot; return true; } } itor->node = NULL; itor->slot = 0; return false; }