Currently there are 5 (or more?) ways of handling key-value pairs in SWI-Prolog:
- library(pairs), with either unordered or ordered elements (cf library(ordsets)).
- library(assoc)
- library(rbtrees)
- dicts
They all provide roughly the same set of functionality, but with different performance/storage costs. Their interfaces are inconsistent, e.g.
-
member(K-V, List),memberchk(K-V, List),ord_memberchk(K-V, List). -
get_assoc(Key, Assoc, Value),gen_assoc(Key, Assoc, Value) -
rb_lookup(Key, Value, Rbtree),rb_in(Key, Value, Rbtree) get_dict(Key, Dict, Value)
I propose creating a new library(kv_pairs) that provides a unified set of lookup/update/delete predicates.
I have two reasons for doing this:
- Itās not obvious which data structure provides best performance, so itās nice to be able to change algorithms by changing only the data structure creation calls.
- Leverage the existing test cases for all the algorithms.
If this new library seems like a good idea, Iāll write up a proposal for the unified predicates.