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 
  18   hashtable_size=$4000;
\r 
  21   thashitem=class(tlinklist)
\r 
  26   thashtable=array[0..hashtable_size-1] of thashitem;
\r 
  27   phashtable=^thashtable;
\r 
  29 {adds "item" to the tree for name "s". the name must not exist (no checking done)}
\r 
  30 procedure addtree(t:phashtable;s:ansistring;item:pointer);
\r 
  32 {removes name "s" from the tree. the name must exist (no checking done)}
\r 
  33 procedure deltree(t:phashtable;s:ansistring);
\r 
  35 {returns the item pointer for s, or nil if not found}
\r 
  36 function findtree(t:phashtable;s:ansistring):pointer;
\r 
  38 {clear a hashtable, deallocating all used resources}
\r 
  39 procedure cleartree(t:phashtable);
\r 
  43 //FNV-1a hash function
\r 
  44 function makehash(s:ansistring):integer;
\r 
  54   for a := 1 to b do begin
\r 
  55     h := (h xor byte(s[a])) * 16777619;
\r 
  57   result := h and (hashtable_size-1);
\r 
  60 procedure addtree(t:phashtable;s:ansistring;item:pointer);
\r 
  65   hash := makehash(s);
\r 
  66   p := thashitem.create;
\r 
  70   linklistadd(tlinklist(t[hash]),tlinklist(p));
\r 
  73 procedure deltree(t:phashtable;s:ansistring);
\r 
  78   hash := makehash(s);
\r 
  81   while p <> nil do begin
\r 
  82     if p.s = s then begin
\r 
  86     p := thashitem(p.next);
\r 
  88   linklistdel(tlinklist(t[hash]),tlinklist(p2));
\r 
  93 function findtree(t:phashtable;s:ansistring):pointer;
\r 
  99   hash := makehash(s);
\r 
 101   while p <> nil do begin
\r 
 102     if p.s = s then begin
\r 
 106     p := thashitem(p.next);
\r 
 110 procedure cleartree(t:phashtable);
\r 
 115   for hash := 0 to hashtable_size-1 do begin
\r 
 117     while p <> nil do begin
\r 
 118       p2 := thashitem(p.next);
\r 
 119       linklistdel(tlinklist(t[hash]),tlinklist(p));
\r 
 121       p := thashitem(p2);
\r