Suggested changes to fcl-stl/ghashmap.pp
Original Reporter info from Mantis: lks
-
Reporter name:
Original Reporter info from Mantis: lks
- Reporter name:
Description:
This is a follow-up to the recent changes in fcl-stl (e.g. http://bugs.freepascal.org/view.php?id=23938).
I have been using for a while a modified version of ghashmap.pp, and I submit it for your consideration for inclusion in the fpc trunk.
Summary of changes:
-
the current version hard-codes a loading factor of 5; I have changed this to be the constant maxLoadingFactor with a default of 1.0 (more typical of typical STL packages). By the way, it wouldn't be hard to make maxLoadingFactor dynamically settable as part of the THashmap class, but I didn't do that.
-
Added a method THashmap.GetValue(key: TKey; out value: TValue): boolean, as there was no easy way to retrieve a value before in one atomic operation if you didn't already know it existed.
-
Some fixes for architectures where sizeof(longint) <> sizeof(SizeUInt). Also, a number of types were changed to SizeUInt because gvector generally assumes SizeUInt
-
Fixed where the code assumed that a SizeUInt variable could never be negative
-
Eliminated inline directives in the implementation section, as they are not needed (similar to fix applied in gvector.pp)
-
Added a THashmapIterator.Prev function
-
Added THashmap.erase(iter: TIterator) procedure, so that one can walk a hashtable and delete an element that meet a certain condition. The cursor is moved back to the previous element.
-
[Non backwards compatible change, can be enabled with an ifdef] Extended the THash class to not only have a class hash function, but also a class equal function. Useful, for example, when doing case-insensitive string compares.
Mantis conversion info:
- Mantis ID: 23943
- Build: Revision 23647
- Platform: all
- Version: 2.7.1
- Fixed in version: 3.1.1
- Fixed in revision: 33341 (#493db556)
- Monitored by: » stefc (stefc), » heX (heX)
- Target version: 3.0.2