Module maps

This module provides unordered maps. The unordered maps are represented by lists of key value pairs [k1-v1, .., kn-vn]. The lists need not be key ordered or key duplicate free. During operations for duplicates the first key wins:

Examples:
?- get([2-a,1-b], 1, X).
X = b
?- put([2-a,1-b], 1, c, X).
X = [2-a,1-c]

The realization uses a membership check based on (==)/2. As a result the predicates are safe to be used with non-ground terms. On the other hand, since this comparison is not arithmetical, 1 and 1.0 are for example considered different.

The following maps predicates are provided:

get(M, K, V):
The predicate succeeds for the value V associated with the key K in the map M.
put(M, K, V, N):
The predicate succeeds for a map N where the value V is associated with the key K and the other key values are associated as in the map M.
remove(M, K, N):
The predicate succeeds for a map N where the key K has no value and the other key values are associated as in the map M.

Kommentare