1 { Copyright (C) 2005 Bas Steendijk and Peter Green
\r
2 For conditions of distribution and use, see copyright notice in zlib_license.txt
\r
3 which is included in the package
\r
4 ----------------------------------------------------------------------------- }
\r
6 {actually a hashtable. it was a tree in earlier versions}
\r
15 hashtable_size=$4000;
\r
18 thashitem=class(tlinklist)
\r
23 thashtable=array[0..hashtable_size-1] of thashitem;
\r
24 phashtable=^thashtable;
\r
26 {adds "item" to the tree for name "s". the name must not exist (no checking done)}
\r
27 procedure addtree(t:phashtable;s:ansistring;item:pointer);
\r
29 {removes name "s" from the tree. the name must exist (no checking done)}
\r
30 procedure deltree(t:phashtable;s:ansistring);
\r
32 {returns the item pointer for s, or nil if not found}
\r
33 function findtree(t:phashtable;s:ansistring):pointer;
\r
37 function makehash(s:ansistring):integer;
\r
45 for a := 1 to b do begin
\r
46 result := (result shl shifter) xor byte(s[a]);
\r
48 result := (result xor result shr 16) and (hashtable_size-1);
\r
51 procedure addtree(t:phashtable;s:ansistring;item:pointer);
\r
56 hash := makehash(s);
\r
57 p := thashitem.create;
\r
61 linklistadd(tlinklist(t[hash]),tlinklist(p));
\r
64 procedure deltree(t:phashtable;s:ansistring);
\r
69 hash := makehash(s);
\r
72 while p <> nil do begin
\r
73 if p.s = s then begin
\r
77 p := thashitem(p.next);
\r
79 linklistdel(tlinklist(t[hash]),tlinklist(p2));
\r
84 function findtree(t:phashtable;s:ansistring):pointer;
\r
90 hash := makehash(s);
\r
92 while p <> nil do begin
\r
93 if p.s = s then begin
\r
97 p := thashitem(p.next);
\r