Re: [eclipse-users] Fast lookup mapping.

From: Joachim Schimpf (Independent Contractor) <"Joachim>
Date: Tue, 27 Mar 2007 13:13:42 +0100
Malcolm Ryan wrote:
> I'm looking for a prolog data-structure which implements O(1) lookup  
> on keys, and which can take a prolog variable as a possible key. That  
> is, I want it to be functionally equivalent to:
> get(X, [(Key,Value) | _], Value) :-
> 	X == Key, !.
> get(X, [_, Tail], Value) :-
> 	get(X, Tail, Value).
> The use of '==' is important.

Variables do not by default have an immutable property
that could be used as an index or hash key (==/2 effectively
compares the variable addresses, which cannot be used as a key
because they can change due to garbage collection etc).

You could generate a unique number for each interesting
variable, store it in a variable attribute, and use that
as a key for lib(hash).  Or - if you only need a single
lookup table - you could store the data in the attribute

-- Joachim
Received on Tue Mar 27 2007 - 13:13:59 CEST

This archive was generated by hypermail 2.3.0 : Sat Aug 24 2019 - 06:15:04 CEST