From: beware Date: Fri, 12 Oct 2012 18:47:00 +0000 (+0000) Subject: add cleartree to bsearchtree which clears a hashtable and frees all resources X-Git-Url: http://www.lcore.org/git/lcore.git/commitdiff_plain/c1c7500bc32248d67b6cf7903a6db7b15e2cd1c9 add cleartree to bsearchtree which clears a hashtable and frees all resources git-svn-id: file:///svnroot/lcore/trunk@122 b1de8a11-f9be-4011-bde0-cc7ace90066a --- diff --git a/bsearchtree.pas b/bsearchtree.pas index d9e3ea2..9dc355e 100644 --- a/bsearchtree.pas +++ b/bsearchtree.pas @@ -32,6 +32,9 @@ procedure deltree(t:phashtable;s:ansistring); {returns the item pointer for s, or nil if not found} function findtree(t:phashtable;s:ansistring):pointer; +{clear a hashtable, deallocating all used resources} +procedure cleartree(t:phashtable); + implementation function makehash(s:ansistring):integer; @@ -98,4 +101,20 @@ begin end; end; +procedure cleartree(t:phashtable); +var + hash:integer; + p,p2:thashitem; +begin + for hash := 0 to hashtable_size-1 do begin + p := t[hash]; + while p <> nil do begin + p2 := thashitem(p.next); + linklistdel(tlinklist(t[hash]),tlinklist(p)); + p.destroy; + p := thashitem(p2); + end; + end; +end; + end.