Quick-Dict or Hash-List : value by key and key by value?

56 Views Asked by At

Invented quick and dirty Hash-like using a list i.e.

 [ key1:val1,key2:val2, ....]

I can get the keys and values :

hl_keys(HL,Res) :- maplist(\I^K^(I = K:_),HL,Res).
hl_vals(HL,Res) :- maplist(\I^V^(I = _:V),HL,Res).

but how do I get specific value by key and key by value ?

1

There are 1 best solutions below

1
sten On

it was easy :

hl_val(HL,Key,Res) :- member(Key:Res,HL).
hl_key(HL,Val,Res) :- member(Res:Val,HL).

and the good thing is it acts as two-way hash