Forum > General

[SOLVED] Hash list with integer as key

<< < (4/5) > >>

MathMan:

--- Quote from: Leledumbo on December 17, 2014, 04:56:50 am ---
--- Quote from: Dibo on December 17, 2014, 01:12:24 am ---Well, I just used EpickTimer. This is my whole unit, nothing amazing, just connect events to buttons:

--- End quote ---
Tested myself, it's amazing to know how TFPGMap can beat all other maps though this might be key type specific. THashmap depends much on the hash function, but even a simple `a mod n` is not enough to beat TFPGMap. The final result is a tight gap on insertion, on searching both are equal.

--- End quote ---

Hi Leledumbo,

I got intriqued and wanted to take a look. Only found the sources in fgl.pp which are unfortunately "reluctantly commented" and an old post from 2010 when there wasn't one available. Has that changed since?

Regards,
MathMan

Leledumbo:

--- Quote from: MathMan on December 17, 2014, 11:50:08 pm ---I got intriqued and wanted to take a look. Only found the sources in fgl.pp which are unfortunately "reluctantly commented" and an old post from 2010 when there wasn't one available. Has that changed since?

--- End quote ---
Nope I guess. The latest changes to fgl unit seems to be the addition of enumerator to some classes but that's all AFAIR. No documentation yet, and the unit status seems still the same: testing unit for fpc generics support

Khumarahn:
Hi. I am a novice.

I need a reasonably fast map<string, integer>. I tried TFPGMap on a very simple example:

--- Code: ---Program Lesson1_Program1;   

uses fgl, sysutils;

type
  TMap = Specialize TFPGMap<string, integer>;

var
  Map: TMap;
  i: longint;
Begin
 Map := TMap.Create;
 for i:=0 to 100000 do
   Map['item #' + IntToStr(i)] := i;
End.
--- End code ---

and running it takes 1 minute and 30 seconds on a relatively new i5 processor. It looks very slow. Did I make a mistake somewhere? Or I should look for some other data structure?

Leledumbo:

--- Quote from: Khumarahn on August 06, 2015, 10:50:18 pm ---Did I make a mistake somewhere?

--- End quote ---
Nope, it's just not a map in the sense of hash map. TFPGMap is a list with map-like behavior. ghashmap from fcl-stl package should give what you want, but currently only available and working correctly in either 3.0 fixes branch or trunk. 2.6.4 won't do.

Khumarahn:
ok, thank you much. It is very weird that map is still not implemented - pascal is an old language...

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version