[m-dev.] [revised] for review: bintree_set.m -- open type /representation/

doug.auclair at logicaltypes.com doug.auclair at logicaltypes.com
Thu Feb 16 03:29:16 AEDT 2006


Dear all, as per Ralph's posting, this is a revised implementation of bintree_set that exports an one-way representation (protected by protocol, representation/2 is one way) of bintree_set's internal structure that does not compromise the ordering of the elements of the set.  Please review and update the library.

N.B. the auxiliary predicate (representation_aux/2) is necessary to do the actual work of converting a bintree 
/representation/ to a bintree_set representation ... i.e. the ordering of bintree is protected by protocol even from bintree_set.

Sincerely,
Douglas M. Auclair

$ diff -u merc-0.12.1/library/bintree_set.sav merc-0.12.1/library/bintree_set.m
--- bintree_set.sav     2006-02-15 01:01:58.000000000 -0500
+++ bintree_set.m       2006-02-15 11:29:14.000000000 -0500
@@ -25,6 +25,10 @@
 :- import_module list.
 
 :- type bintree_set(_T).
+:- type bintree_set_representation(T) --->
+   tree_set(T, bintree_set_representation(T), bintree_set_representation(T))
+   ;
+   empty_tree.
 
        % `bintree_set__list_to_set(List, Set)' is true iff `Set' is the set
        % containing only the members of `List'.
@@ -156,11 +160,15 @@
 :- func bintree_set__intersect(bintree_set(T), bintree_set(T))
        = bintree_set(T).
 
+:- pred bintree_set.representation(bintree_set(T)::in,
+                                  bintree_set_representation(T)::out)
+                                  is det.
+
 %--------------------------------------------------------------------------%
 
 :- implementation.
 :- import_module bintree, assoc_list.
-:- import_module std_util.
+:- import std_util.
 
 :- type bintree_set(T)          ==      bintree(T, unit).
 
@@ -300,3 +308,17 @@
 
 bintree_set__intersect(BT1, BT2) = BT3 :-
        bintree_set__intersect(BT1, BT2, BT3).
+
+bintree_set.representation(Set, SetRepresentation) :-
+  bintree.representation(Set, BintreeRepresentation),
+  bintree_set.representation_aux(BintreeRepresentation, SetRepresentation).
+
+:- pred bintree_set.representation_aux(bintree_representation(K, unit)::in,
+                                      bintree_set_representation(K)::out)
+                                      is det.
+bintree_set.representation_aux(empty_assoc_tree, empty_tree).
+bintree_set.representation_aux(assoc_tree(Datum, unit, Left, Right),
+                              tree_set(Datum, Left1, Right1)) :-
+  bintree_set.representation_aux(Left, Left1),
+  bintree_set.representation_aux(Right, Right1).


--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list