[m-dev.] for review: use bitsets in quantification
Simon Taylor
stayl at cs.mu.OZ.AU
Fri Nov 10 17:18:25 AEDT 2000
Fergus wrote:
> OK, I'll give up on `..` for now, and go back to just wanting to be
> able to support a dense_bitset type. For that type, I need `first'
> and `last' methods. I guess it doesn't strictly *need* contiguous
> to_int values, though.
I think it's better to leave the `enum' class as it is for now,
rather than add stuff which may or may not be useful later.
We can add a `bounded_enum' class derived from `enum'
for the `enum_first' and `enum_last' methods.
Here's a relative diff dealing with Fergus' recent review comments.
I intend to commit this soon, unless anyone objects.
Simon.
--- enum.m 2000/11/10 05:33:07 1.2
+++ enum.m 2000/11/10 05:58:40
@@ -5,11 +5,15 @@
%-----------------------------------------------------------------------------%
% File: enum.m.
% Author: stayl.
-% Stability: low.
+% Stability: very low.
%
% This module provides the typeclass `enum', which describes
% types which can be converted to and from integers without loss
% of information.
+%
+% The interface of this module is likely to change.
+% At the moment it is probably best to only use the `enum'
+% type class for types to be stored in `sparse_bitset's.
%
%-----------------------------------------------------------------------------%
--- int.m 2000/11/10 05:27:35 1.3
+++ int.m 2000/11/10 05:29:01
@@ -221,7 +221,11 @@
% Used by floor_to_multiple_of_bits_per_int, placed
% here to make sure they go in the `.opt' file.
-:- func int__div_bits_per_int(int) = int.
+
+ % int__quot_bits_per_int(X) = X // bits_per_int.
+:- func int__quot_bits_per_int(int) = int.
+
+ % int__times_bits_per_int(X) = X * bits_per_int.
:- func int__times_bits_per_int(int) = int.
%-----------------------------------------------------------------------------%
@@ -313,7 +317,7 @@
:- pragma inline(floor_to_multiple_of_bits_per_int/1).
floor_to_multiple_of_bits_per_int(X) = Floor :-
- Trunc = div_bits_per_int(X),
+ Trunc = quot_bits_per_int(X),
Floor0 = times_bits_per_int(Trunc),
( Floor0 > X ->
Floor = Floor0 - bits_per_int
@@ -476,7 +480,7 @@
Bits = ML_BITS_PER_INT;
").
-:- pragma c_code(int__div_bits_per_int(Int::in) = (Div::out),
+:- pragma c_code(int__quot_bits_per_int(Int::in) = (Div::out),
[will_not_call_mercury, thread_safe], "
Div = Int / ML_BITS_PER_INT;
").
--- sparse_bitset.m 2000/11/10 06:00:01 1.4
+++ sparse_bitset.m 2000/11/10 06:01:09
@@ -433,8 +433,13 @@
bits_for_index(Index, Offset, Bits),
Set = [make_bitset_elem(Offset, Bits) | Set0]
; BitToSet = Index - Offset0, BitToSet < bits_per_int ->
- Bits = set_bit(Data0 ^ bits, BitToSet),
- Set = [make_bitset_elem(Offset0, Bits) | Rest]
+ Bits0 = Data0 ^ bits,
+ ( get_bit(Bits0, BitToSet) \= 0 ->
+ Set = Set0
+ ;
+ Bits = set_bit(Bits0, BitToSet),
+ Set = [make_bitset_elem(Offset0, Bits) | Rest]
+ )
;
Set = [Data0 | insert_2(Rest, Index)]
).
--------------------------------------------------------------------------
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