[m-rev.] implement map__inverse_search using map__member

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Dec 5 20:34:29 AEDT 2003


Estimated hours taken: 0.25
Branches: main

library/map.m:
	Fix an XXX: define map__inverse_search using map__member, rather
	than by converting the map to an assoc list and searching that.
	This is simpler, and should be more efficient, since it avoids
	unnecessary heap allocation.

Workspace: /home/ceres/fjh/mercury
Index: library/map.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/map.m,v
retrieving revision 1.85
diff -u -d -r1.85 map.m
--- library/map.m	5 Nov 2003 08:53:43 -0000	1.85
+++ library/map.m	1 Dec 2003 04:54:24 -0000
@@ -601,26 +601,8 @@
 
 %-----------------------------------------------------------------------------%
 
-	% XXX inefficient
-
 map__inverse_search(Map, V, K) :-
-	tree234__tree234_to_assoc_list(Map, AssocList),
-	assoc_list_member(K, V, AssocList).
-
-%-----------------------------------------------------------------------------%
-
-	% The code here is deliberately written using very simple
-	% modes.
-	% The reason we don't just use member/2 is that we want to
-	% bootstrap this thing ASAP.
-
-:- pred assoc_list_member(K, V, list(pair(K,V))).
-:- mode assoc_list_member(in, out, in) is nondet.
-:- mode assoc_list_member(out, in, in) is nondet.
-:- mode assoc_list_member(in, in, in) is semidet.
-assoc_list_member(K, V, [K - V | _]).
-assoc_list_member(K, V, [_ | Xs]) :-
-	assoc_list_member(K, V, Xs).
+	map__member(Map, V, K).
 
 %-----------------------------------------------------------------------------%
 

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list