Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2017-09

Container class for key-value pairs

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Santhoff

Hi,

since I'm programming Pascal only on occasion I'd like to know:

Which container class ist the easiest to use for key-value pairs?

The goal is to store a configuration set from a hardware measuring device having 81 items. This item set is fixed, no change. The values are parsed from json data (text) and have to be stored in memory (for now).

TIA,
Marc

Marc Santhoff

Reply by email

Michael Van Canneyt
to Marc Santhoff
Marc Santhoff wrote 10 lines
Hi, since I'm programming Pascal only on occasion I'd like to know: Which container class ist the easiest to use for key-value pairs? The goal is to store a configuration set from a hardware measuring device having 81 items. This item set is fixed, no change. The values are parsed from json data (text) and have to be stored in memory (for now).

You have several options. Plain TStringlist is easy to use: https://www.freepascal.org/docs-html/current/rtl/classes/tstringlist.html

Inifiles contains a tstrings descendent which is optimized for name/value pairs: https://www.freepascal.org/docs-html/current/fcl/inifiles/thashedstringlist.html

contnrs unit contains TFPStringHashTable:
https://www.freepascal.org/docs-html/current/fcl/contnrs/tfpstringhashtable.html

TFPGMap from unit fgl can be used to create key/value map.

No doubt there are other options still.

Michael.

Reply by email

leledumbo
to Marc Santhoff: since I'm programming Pascal only on occasion I'd like to know: Which container class ist…
Which container class ist the easiest to use for key-value pairs?

All are just as easy. Instead you should state for non-functional requirements. Does it have to be fast? Does it have to be memory efficient? Or as long as you can access it as key-value then it would be fine no matter what the implementation is?

Reply by email

Marc Santhoff
to Michael Van Canneyt: You have several options. Plain TStringlist is easy to use:…
Michael Van Canneyt wrote 16 lines
On Mon, 11 Sep 2017, Marc Santhoff wrote: > Hi, > > since I'm programming Pascal only on occasion I'd like to know: > > Which container class ist the easiest to use for key-value pairs? > > The goal is to store a configuration set from a hardware measuring > device having 81 items. This item set is fixed, no change. The values > are parsed from json data (text) and have to be stored in memory (for > now). You have several options. Plain TStringlist is easy to use: https://www.freepascal.org/docs-html/current/rtl/classes/tstringlist.html

Used all the time without thinking about it. ;)

contnrs unit contains TFPStringHashTable: https://www.freepascal.org/docs-html/current/fcl/contnrs/tfpstringhashtable.html TFPGMap from unit fgl can be used to create key/value map.

Two intresting alternatives to look at.

No doubt there are other options still.

I think so, too. My first action will be to have a deep look at the unit fpjson. Hopefully I can re-use the containers therein without any extra pushing around of data bits in memory.

Thanks for showing some directions,
Marc

Reply by email

Marc Santhoff
to leledumbo: All are just as easy. Instead you should state for non-functional requirements. Does it…
leledumbo wrote 6 lines
> Which container class ist the easiest to use for key-value pairs? All are just as easy. Instead you should state for non-functional requirements. Does it have to be fast? Does it have to be memory efficient? Or as long as you can access it as key-value then it would be fine no matter what the implementation is?

I fully agree with you in having to look at other requirements is important.

But there are none this time. 81 Items do never eat much memory, they are small an few enough to be fast and configurations are read and maybe written only sparingly.

Thank you nonetheless,
Marc

Reply by email