[m-rev.] diff: improve error handling in bitmap.m and hash_table.m
Simon Taylor
stayl at cs.mu.OZ.AU
Wed Oct 24 17:28:11 AEST 2001
Estimated hours taken: 0.1
library/bitmap.m:
library/hash_table.m:
For consistency with the other library modules,
throw `require__software_error' exceptions rather
than just raw strings.
Index: bitmap.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/bitmap.m,v
retrieving revision 1.4
diff -u -u -r1.4 bitmap.m
--- bitmap.m 9 May 2001 15:21:59 -0000 1.4
+++ bitmap.m 24 Oct 2001 07:18:09 -0000
@@ -140,7 +140,7 @@
:- implementation.
-:- import_module exception.
+:- import_module exception, require.
% A bitmap is represented as an array of ints where each int stores
% int__bits_per_int bits. The first element of the array (index 0)
@@ -157,7 +157,7 @@
new(N, B) = BM :-
( if N < 0 then
- throw("bitmap__new: negative size")
+ throw(software_error("bitmap__new: negative size"))
else
X = initializer(B),
BM0 = (array__init(num_ints_required(N), X) ^ elem(0) := N),
@@ -226,19 +226,19 @@
set(BM, I) =
( if in_range(BM, I)
then BM ^ elem(int_offset(I)) := BM ^ elem(int_offset(I)) \/ bitmask(I)
- else throw("bitmap__set: out of range")
+ else throw(software_error("bitmap__set: out of range"))
).
clear(BM, I) =
( if in_range(BM, I)
then BM ^ elem(int_offset(I)) := BM ^ elem(int_offset(I)) /\ \bitmask(I)
- else throw("bitmap__clear: out of range")
+ else throw(software_error("bitmap__clear: out of range"))
).
flip(BM, I) =
( if in_range(BM, I)
then BM ^ elem(int_offset(I)) := BM ^ elem(int_offset(I)) `xor` bitmask(I)
- else throw("bitmap__flip: out of range")
+ else throw(software_error("bitmap__flip: out of range"))
).
% ---------------------------------------------------------------------------- %
@@ -257,13 +257,13 @@
is_set(BM, I) :-
( if in_range(BM, I)
then BM ^ elem(int_offset(I)) /\ bitmask(I) \= 0
- else throw("bitmap__is_set: out of range")
+ else throw(software_error("bitmap__is_set: out of range"))
).
is_clear(BM, I) :-
( if in_range(BM, I)
then BM ^ elem(int_offset(I)) /\ bitmask(I) = 0
- else throw("bitmap__is_clear: out of range")
+ else throw(software_error("bitmap__is_clear: out of range"))
).
% ---------------------------------------------------------------------------- %
Index: hash_table.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/hash_table.m,v
retrieving revision 1.1
diff -u -u -r1.1 hash_table.m
--- hash_table.m 9 Feb 2001 13:58:50 -0000 1.1
+++ hash_table.m 24 Oct 2001 06:50:26 -0000
@@ -181,7 +181,7 @@
:- implementation.
-:- import_module exception, math, bool, exception, list, std_util.
+:- import_module math, bool, exception, list, require, std_util.
@@ -229,11 +229,13 @@
new(HashPred, N, MaxOccupancy) = HT :-
( if N =< 1 then
- throw("hash_table__new_hash_table: N =< 1")
+ throw(software_error("hash_table__new_hash_table: N =< 1"))
else if N >= int__bits_per_int then
- throw("hash_table__new_hash_table: N >= int__bits_per_int")
+ throw(software_error(
+ "hash_table__new_hash_table: N >= int__bits_per_int"))
else if MaxOccupancy =< 0.0 ; 1.0 =< MaxOccupancy then
- throw("hash_table__new_hash_table: MaxOccupancy not in (0.0, 1.0)")
+ throw(software_error(
+ "hash_table__new_hash_table: MaxOccupancy not in (0.0, 1.0)"))
else
NumBuckets = 1 << N,
MaxOccupants = ceiling_to_int(float(NumBuckets) * MaxOccupancy),
@@ -335,7 +337,7 @@
det_insert(HT, K, V) =
( if bitmap__is_set(HT ^ bitmap, H) then
- throw("hash_table__det_insert: key already present")
+ throw(software_error("hash_table__det_insert: key already present"))
else if HT ^ num_occupants = HT ^ max_occupants then
set(expand(HT), K, V)
else
@@ -352,7 +354,7 @@
det_update(HT, K, V) =
( if bitmap__is_clear(HT ^ bitmap, H) then
- throw("hash_table__det_update: key not found")
+ throw(software_error("hash_table__det_update: key not found"))
else
HT ^ values ^ elem(H) := V
)
@@ -364,7 +366,7 @@
lookup(HT, K) =
( if search(HT, K, V)
then V
- else throw("hash_table__lookup: key not found")
+ else throw(software_error("hash_table__lookup: key not found"))
).
elem(K, HT) = lookup(HT, K).
--------------------------------------------------------------------------
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