add cleartree to bsearchtree which clears a hashtable and frees all resources
authorbeware <beware@bircd.org>
Fri, 12 Oct 2012 18:47:00 +0000 (18:47 +0000)
committerbeware <beware@bircd.org>
Fri, 12 Oct 2012 18:47:00 +0000 (18:47 +0000)
git-svn-id: file:///svnroot/lcore/trunk@122 b1de8a11-f9be-4011-bde0-cc7ace90066a

bsearchtree.pas

index d9e3ea26523f94a13b1c8819b38301725061e6de..9dc355e08a1b389575789363052d607393df5519 100644 (file)
@@ -32,6 +32,9 @@ procedure deltree(t:phashtable;s:ansistring);
 {returns the item pointer for s, or nil if not found}\r
 function findtree(t:phashtable;s:ansistring):pointer;\r
 \r
+{clear a hashtable, deallocating all used resources}\r
+procedure cleartree(t:phashtable);\r
+\r
 implementation\r
 \r
 function makehash(s:ansistring):integer;\r
@@ -98,4 +101,20 @@ begin
   end;\r
 end;\r
 \r
+procedure cleartree(t:phashtable);\r
+var\r
+  hash:integer;\r
+  p,p2:thashitem;\r
+begin\r
+  for hash := 0 to hashtable_size-1 do begin\r
+    p := t[hash];\r
+    while p <> nil do begin\r
+      p2 := thashitem(p.next);\r
+      linklistdel(tlinklist(t[hash]),tlinklist(p));\r
+      p.destroy;\r
+      p := thashitem(p2);\r
+    end;\r
+  end;\r
+end;\r
+\r
 end.\r