6

It's incredibly impossible to find things for FreePascal because all searches end up at some sort of Delphi related site.

Is there a built-in Dictionary object?

This page references "TDictionary" under the Generic Classes section, but I have no idea what unit it might be in, or if it even exists.

Name McChange
  • 2,750
  • 5
  • 27
  • 46
  • 3
    Unit `fgl` contains generic classes defined [`here`](http://wiki.freepascal.org/Generics#Introduction). An example using `TFPGMap`: [`Class Map or Dictionary, anyone?`](http://www.lazarus.freepascal.org/index.php?topic=18441.0). – LU RD Apr 03 '13 at 09:04
  • 2
    Closest, indeed, is fgl.TFPGMap I think. LU RD: make it a proper answer so that it can be accepted. – Marco van de Voort Apr 03 '13 at 10:02
  • 1
    To Google articles prepend "fpc pascal" to your searches – Ian Macintosh Mar 05 '15 at 01:28

2 Answers2

6

The unit fgl contains the basic generic classes for freepascal.

Among those classes, the closest to a TDictionary is TFPGMap.

An example how to use this class can be found here: Class Map or Dictionary, anyone?.

LU RD
  • 34,438
  • 5
  • 88
  • 296
  • 1
    Forget about `TFPGMap`. It is implemented as **array**, which is just too slow for any purpose. Even using an actual array would be faster. If you are forced to use it, you need to set `sorted` to true, then it uses at least a binary search for reading rather than a linear one. – BeniBela Oct 01 '16 at 12:34
  • 1
    @BeniBela so what did you end up using? – Redoman May 05 '17 at 11:14
  • 2
    @jj_ First I [benchmarked them all](http://www.benibela.de/fpc-map-benchmark_en.html). Rtl-generics seem to be the best overall, but I do not trust them below fpc 3.1. (complex generics are tricky, even Lazarus crashed when I opened their source) ghashmap.THashMap is an okay fallback. Although I ended up using the hash map from Bero's [Fast Light Regular Expressions library](https://github.com/BeRo1985/flre), because I was already using that library for regexs and it is surprisingly fast – BeniBela May 07 '17 at 23:27
  • Thanks! Good source of updated info for someone new to Free Pascal. – Redoman May 09 '17 at 05:01
5

You can use very compatible TDictionary from Generics.Collections unit:

works for FPC trunk rev. 30239 and newer.

Edit 05.08.2016

Generics.Collections library has been added to FPC trunk as rtl-generics package in r34229. Latest version of precompiled FPC trunk (with Generics.Collections) for Win32 + Lazarus trunk available at http://newpascal.org . The repository of Generics.Collections ( https://github.com/dathox/generics.collections ) will be still used for maintenance (should be synced often with FPC trunk).

HNB
  • 297
  • 3
  • 7