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)).
They all provide roughly the same set of functionality, but with different performance/storage costs. Their interfaces are inconsistent, e.g.
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.