[m-rev.] diff: bitmap in java
Peter Wang
novalazy at gmail.com
Fri Jan 8 11:04:14 AEDT 2010
Branches: main
library/bitmap.m:
Add a constructor for the Java definition of MercuryBitmap which allows
foreign code to construct a MercuryBitmap from an existing byte array.
Add an `equals' method implementation.
Fix bitmap_equal in Java. The old definition could return true two
bitmaps had different number of bits but the same number of bytes in
the underlying array.
diff --git a/library/bitmap.m b/library/bitmap.m
index 8c3d6f5..f17fa4d 100644
--- a/library/bitmap.m
+++ b/library/bitmap.m
@@ -1541,8 +1541,28 @@ public static class MercuryBitmap {
public byte[] elements;
public MercuryBitmap(int numBits) {
- num_bits = numBits;
- elements = new byte[numBits / 8 + (((numBits % 8) != 0) ? 1 : 0)];
+ this.num_bits = numBits;
+ this.elements = new byte[numBits / 8 + (((numBits % 8) != 0) ? 1 : 0)];
+ }
+
+ public MercuryBitmap(int numBits, byte[] elements) {
+ // This is provided so that foreign code can construct bitmaps from an
+ // existing byte array.
+ this.num_bits = numBits;
+ this.elements = elements;
+ }
+
+ @Override
+ public boolean equals(Object that) {
+ if (this == that) {
+ return true;
+ }
+ if (that instanceof MercuryBitmap) {
+ MercuryBitmap other = (MercuryBitmap)that;
+ return this.num_bits == other.num_bits
+ && java.util.Arrays.equals(this.elements, other.elements);
+ }
+ return false;
}
}
").
@@ -1585,7 +1605,7 @@ public class MercuryBitmap {
bitmap_equal(BM1::in, BM2::in),
[will_not_call_mercury, thread_safe, promise_pure, will_not_modify_trail],
"
- succeeded = java.util.Arrays.equals(BM1.elements, BM2.elements);
+ succeeded = BM1.equals(BM2);
").
:- pragma foreign_proc("Erlang",
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list