Difference between revisions of "StringHashMap"

From Free Pascal wiki
Jump to navigationJump to search
(→‎See also: FreePascal hash maps comparsion)
 
(4 intermediate revisions by 4 users not shown)
Line 2: Line 2:
 
StringHashMap is a string -> pointer associative map container. It is implemented in a fast and memory efficient way.
 
StringHashMap is a string -> pointer associative map container. It is implemented in a fast and memory efficient way.
 
The search time of a hash map is constant, it does not depend on the amount of data (assuming there is enough memory and no swapping).
 
The search time of a hash map is constant, it does not depend on the amount of data (assuming there is enough memory and no swapping).
Hundreds of thousands of elements is no problem.
+
Millions of elements is no problem.
  
 
The unit name is StrHashMap.pas and it was modified from unit JclStrHashMap.pas which is part of Jcl library.
 
The unit name is StrHashMap.pas and it was modified from unit JclStrHashMap.pas which is part of Jcl library.
Line 12: Line 12:
 
* Source unit file
 
* Source unit file
 
* Comprehensive demo program which builds a database of South Park episodes and then searches them swiftly using a hash map lookup :-)
 
* Comprehensive demo program which builds a database of South Park episodes and then searches them swiftly using a hash map lookup :-)
* README.txt file which basically tells you about this document and the demo program.
+
* README.txt file which basically tells you about this document and about the demo program.
  
 
=== Author ===
 
=== Author ===
Line 55: Line 55:
 
* Iterating elements
 
* Iterating elements
 
* Using the data pointer as integer, making a very efficient word counter.
 
* Using the data pointer as integer, making a very efficient word counter.
 +
 +
=== See also ===
 +
* [[Data Structures, Containers, Collections]] Overview of other hash list/data structure implementations
 +
* [http://www.benibela.de/fpc-map-benchmark_en.html FreePascal hash maps comparsion]
 +
 +
 +
[[Category:Containers]]

Latest revision as of 08:43, 1 August 2018

About

StringHashMap is a string -> pointer associative map container. It is implemented in a fast and memory efficient way. The search time of a hash map is constant, it does not depend on the amount of data (assuming there is enough memory and no swapping). Millions of elements is no problem.

The unit name is StrHashMap.pas and it was modified from unit JclStrHashMap.pas which is part of Jcl library.

The purpose was to make it compile and work with FPC (Free Pascal Compiler). In the process lots of code with conditional compilation directives was removed and also many unit dependencies were removed.

The download contains:

  • Source unit file
  • Comprehensive demo program which builds a database of South Park episodes and then searches them swiftly using a hash map lookup :-)
  • README.txt file which basically tells you about this document and about the demo program.

Author

Juha Manninen <juha dot manninen (at) phnet dot fi>

+ the original authors of Jcl code.

License

This code is licensed under the same terms as Jcl library.

Download

The latest stable release can be found on GitHub: http://github.com/JuhaManninen/Pascal

There is a "Download Source" button available.

Change Log

  • Version 1.0 2009-11-25

Dependencies / System Requirements

  • None. Pure Pascal.

Status: Stable

Issues: It turned out there are about similar container classes in FPC's libraries so this one is not published in CCR. I published it in GitHub instead.

Installation

Just include unit StrHashMap in the "uses" section. Set path for it in project settings if needed.

The HashMapDemo1 Example Application

To install and run:

  • From Example directory open HashMapDemo1.lpi
  • Build it
  • Run it at console so that you can see the output.
  • Inspect the source code based on the output.

The example application first builds a database of South Park episodes and then demonstrates the following features of StringHashMap:

  • Search data records with lightning speed using hash keys.
  • Array syntax: Map[Key]
  • Find function: Map.Find(Key, Pointer)
  • FindData function: Map.FindData(Pointer, Key)
  • Iterating elements
  • Using the data pointer as integer, making a very efficient word counter.

See also