DEADSOFTWARE

mapdef cleanup; renamed some fields; mapdef.txt is RC0 now
[d2df-sdl.git] / src / shared / hashtable.pas
index 190d4e62b57cb9c9b9941bc78dec401239aaf0d2..8aaa522a45bae64530243a8fa031f42b4b035b4f 100644 (file)
@@ -59,7 +59,7 @@ type
         mEntries: TEntryArray;
         mFirstEntry, mLastEntry, cur: Integer;
       public
-        constructor Create (aents: TEntryArray; afirst, alast: Integer);
+        constructor Create (const aents: TEntryArray; afirst, alast: Integer);
         function MoveNext (): Boolean; inline;
         function getCurrent (): ValueT; inline;
         property Current: ValueT read getCurrent;
@@ -70,7 +70,7 @@ type
         mEntries: TEntryArray;
         mFirstEntry, mLastEntry, cur: Integer;
       public
-        constructor Create (aents: TEntryArray; afirst, alast: Integer);
+        constructor Create (const aents: TEntryArray; afirst, alast: Integer);
         function MoveNext (): Boolean; inline;
         function getCurrent (): KeyT; inline;
         property Current: KeyT read getCurrent;
@@ -81,7 +81,7 @@ type
         mEntries: TEntryArray;
         mFirstEntry, mLastEntry, cur: Integer;
       public
-        constructor Create (aents: TEntryArray; afirst, alast: Integer);
+        constructor Create (const aents: TEntryArray; afirst, alast: Integer);
         function MoveNext (): Boolean; inline;
         function getCurrent (): PEntry; inline;
         property Current: PEntry read getCurrent;
@@ -161,9 +161,11 @@ type
 type
   THashIntInt = specialize THashBase<Integer, Integer>;
   THashStrInt = specialize THashBase<AnsiString, Integer>;
+  THashStrStr = specialize THashBase<AnsiString, AnsiString>;
 
 function hashNewIntInt (): THashIntInt;
 function hashNewStrInt (): THashStrInt;
+function hashNewStrStr (): THashStrStr;
 
 
 function u32Hash (a: LongWord): LongWord; inline;
@@ -173,6 +175,13 @@ function joaatHash (constref buf; len: LongWord): LongWord;
 function nextPOT (x: LongWord): LongWord; inline;
 
 
+// for integer keys
+function hiiequ (constref a, b: Integer): Boolean;
+function hiihash (constref k: Integer): LongWord;
+function hsiequ (constref a, b: AnsiString): Boolean;
+function hsihash (constref k: AnsiString): LongWord;
+
+
 implementation
 
 uses
@@ -204,7 +213,7 @@ function hsiequ (constref a, b: AnsiString): Boolean; begin result := (a = b); e
 {$RANGECHECKS OFF}
 function hiihash (constref k: Integer): LongWord;
 begin
-  result := k;
+  result := LongWord(k);
   result -= (result shl 6);
   result := result xor (result shr 17);
   result -= (result shl 9);
@@ -233,6 +242,12 @@ begin
 end;
 
 
+function hashNewStrStr (): THashStrStr;
+begin
+  result := THashStrStr.Create(hsihash, hsiequ);
+end;
+
+
 // ////////////////////////////////////////////////////////////////////////// //
 {$PUSH}
 {$RANGECHECKS OFF}
@@ -945,7 +960,7 @@ end;
 
 
 // ////////////////////////////////////////////////////////////////////////// //
-constructor THashBase.TValEnumerator.Create (aents: TEntryArray; afirst, alast: Integer);
+constructor THashBase.TValEnumerator.Create (const aents: TEntryArray; afirst, alast: Integer);
 begin
   mEntries := aents;
   mFirstEntry := afirst;
@@ -970,7 +985,7 @@ end;
 
 
 // ////////////////////////////////////////////////////////////////////////// //
-constructor THashBase.TKeyEnumerator.Create (aents: TEntryArray; afirst, alast: Integer);
+constructor THashBase.TKeyEnumerator.Create (const aents: TEntryArray; afirst, alast: Integer);
 begin
   mEntries := aents;
   mFirstEntry := afirst;
@@ -995,7 +1010,7 @@ end;
 
 
 // ////////////////////////////////////////////////////////////////////////// //
-constructor THashBase.TKeyValEnumerator.Create (aents: TEntryArray; afirst, alast: Integer);
+constructor THashBase.TKeyValEnumerator.Create (const aents: TEntryArray; afirst, alast: Integer);
 begin
   mEntries := aents;
   mFirstEntry := afirst;