[m-dev.] for review: counter.m

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu Mar 9 18:22:33 AEDT 2000


library/counter.m:
	New module to managing integer counters.

library/library.m:
	Include the new module in the library.

Zoltan.

cvs diff: Diffing .
Index: counter.m
===================================================================
RCS file: counter.m
diff -N counter.m
--- /dev/null	Thu Mar  4 04:20:11 1999
+++ counter.m	Thu Mar  9 18:22:12 2000
@@ -0,0 +1,41 @@
+%-----------------------------------------------------------------------------%
+% Copyright (C) 2000 The University of Melbourne.
+% This file may only be copied under the terms of the GNU Library General
+% Public License - see the file COPYING.LIB in the Mercury distribution.
+%-----------------------------------------------------------------------------%
+%
+% File: counter.m.
+% Author: zs.
+% Stability: high.
+%
+% Predicates for dealing with counters, which are mechanisms for allocating
+% consecutively numbered integers. The abstraction barrier eliminates the
+% possibility of confusion along the lines of "does this counter record
+% the next number to be handed out, or the last number that was handed out?".
+%
+%-----------------------------------------------------------------------------%
+
+:- module counter.
+
+:- interface.
+
+:- type counter.
+
+	% counter_init(N, Counter) returns a counter whose first allocation
+	% will be the integer N.
+:- pred counter__init(int::in, counter::out) is det.
+
+	% counter__allocate(N, Counter0, Counter) takes a counter, and
+	% returns (a) the next integer to be allocated from that counter,
+	% and (b) the updated state of the counter.
+:- pred counter__allocate(int::out, counter::in, counter::out) is det.
+
+:- implementation.
+
+:- import_module int.
+
+:- type counter ---> counter(int).
+
+counter__init(N, counter(N)).
+
+counter__allocate(N, counter(N), counter(N + 1)).
Index: library.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/library.m,v
retrieving revision 1.46
diff -u -b -r1.46 library.m
--- library.m	1999/10/28 06:27:13	1.46
+++ library.m	2000/03/09 02:35:23
@@ -25,7 +25,7 @@
 
 :- import_module array, assoc_list, bag, benchmarking.
 :- import_module bimap, bintree, bintree_set, bool.
-:- import_module bt_array, char, dir, eqvclass, float.
+:- import_module bt_array, char, counter, dir, eqvclass, float.
 :- import_module math, getopt, graph, group, int.
 :- import_module io, list, map, multi_map, pqueue, queue, random, relation.
 :- import_module require, set, set_bbbtree, set_ordlist, set_unordlist, stack.
--------------------------------------------------------------------------
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