From: Vincent Pit Date: Thu, 28 Oct 2010 22:18:08 +0000 (+0200) Subject: Add ptable_delete to ptable.h X-Git-Tag: v0.45~8 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;ds=sidebyside;h=3726dd28139789d99ab213bf25d9a2b0509cb756;p=perl%2Fmodules%2FVariable-Magic.git Add ptable_delete to ptable.h --- diff --git a/ptable.h b/ptable.h index b3d19e2..055f0a5 100644 --- a/ptable.h +++ b/ptable.h @@ -176,6 +176,27 @@ STATIC void PTABLE_PREFIX(_store)(pPTBL_ ptable * const t, const void * const ke } } +STATIC void PTABLE_PREFIX(_delete)(pPTBL_ ptable * const t, const void * const key) { + ptable_ent *prev, *ent; + const size_t i = PTABLE_HASH(key) & t->max; + + prev = NULL; + ent = t->ary[i]; + for (; ent; prev = ent, ent = ent->next) { + if (ent->key == key) + break; + } + + if (ent) { + if (prev) + prev->next = ent->next; + else + t->ary[i] = ent->next; + PTABLE_VAL_FREE(ent->val); + PerlMemShared_free(ent); + } +} + #ifndef ptable_walk STATIC void ptable_walk(pTHX_ ptable * const t, void (*cb)(pTHX_ ptable_ent *ent, void *userdata), void *userdata) { #define ptable_walk(T, CB, UD) ptable_walk(aTHX_ (T), (CB), (UD))