Wed Jan 23, 2019 6:59 am
Login Register Lost Password? Contact Us

DICTIONARY lookup on a range of values.

Questions around writing code and queries

Mon Nov 19, 2018 3:10 pm Change Time Zone


I would like a DICTIONARY to return a value given a probe using a range of key values.
e.g. a RGB triplet the three supplied components could be within +- some range of values to return the same colour (e.g. blue)
Or with dates there is the concept of 'circa 1950' so I would want the value for key 1950 to be returned for any input say 1948 to 1952.
Now I can do this filtering a DATASET: e.g.:
Code: Select all
BOOLEAN GotEvent(integer tgtDate,INTEGER range = 3) := EXISTS(DATASET(date BETWEEN tgtDate-range and tgtDate+range));

and I can do this with a DICTIONARY if every item in the range is specified, e.g.
Code: Select all
DATASET([{1948,'Festival of Britain'}
   ,{1949,'Festival of Britain'}
   ,{1950,'Festival of Britain'}
   ,{1951,'Festival of Britain'}
   ,{1952,'Festival of Britain'}],{integer date,string event})
     {date => event});

But is there a way to use DICTIONARY economically. (I don't mean using a MACRO to expand a dataset to the structure above as that's not clear code nor economical.)

Posts: 337
Joined: Sat Oct 01, 2011 7:26 pm

Mon Nov 19, 2018 6:54 pm Change Time Zone


I don't think DICTIONARY is applicable to this. If you're looking for better performance from the implicit indexing a DICTIONARY gives you, then I'd suggest using your "filtering a DATASET" approach, but use an INDEX instead of a DATASET.


Community Advisory Board Member
Community Advisory Board Member
Posts: 1404
Joined: Wed Oct 26, 2011 7:40 pm

Wed Nov 21, 2018 10:07 am Change Time Zone

Thanks Richard,

As least I know now.

Posts: 337
Joined: Sat Oct 01, 2011 7:26 pm

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest