mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-17 02:13:54 +00:00
Discussion of these changes can be found on the Mercury developers
mailing list archives from June 2018.
COPYING.LIB:
Add a special linking exception to the LGPL.
*:
Update references to COPYING.LIB.
Clean up some minor errors that have accumulated in copyright
messages.
73 lines
1.9 KiB
Java
73 lines
1.9 KiB
Java
//
|
|
// Copyright (C) 2001-2002, 2004-2007, 2009-2011 The University of Melbourne
|
|
// Copyright (C) 2014, 2018 The Mercury Team.
|
|
// This file is distributed under the terms specified in COPYING.LIB.
|
|
//
|
|
|
|
package jmercury.runtime;
|
|
|
|
/**
|
|
* Simple bitmap implementation.
|
|
* This bitmap class is mainly used by bitmap.m in the standard library. It
|
|
* is also used by version_array.m which is why it is part of the
|
|
* jmercury.runtime package rather than being internal to bitmap.m
|
|
*/
|
|
public class MercuryBitmap implements java.io.Serializable {
|
|
public static final int BITS_PER_BYTE = 8;
|
|
public int num_bits;
|
|
public byte[] elements;
|
|
|
|
public MercuryBitmap(int numBits) {
|
|
int num_bytes = (numBits + BITS_PER_BYTE - 1) / BITS_PER_BYTE;
|
|
|
|
this.num_bits = numBits;
|
|
this.elements = new byte[num_bytes];
|
|
}
|
|
|
|
@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;
|
|
}
|
|
|
|
public boolean getBit(int bit)
|
|
{
|
|
return (elements[byteIndexForBit(bit)]
|
|
& (1 << bitIndexWithinByte(bit))) != 0;
|
|
}
|
|
|
|
public void setBit(int bit)
|
|
{
|
|
byte b;
|
|
|
|
b = elements[byteIndexForBit(bit)];
|
|
b |= 1 << bitIndexWithinByte(bit);
|
|
elements[byteIndexForBit(bit)] = b;
|
|
}
|
|
|
|
public void clearBit(int bit)
|
|
{
|
|
byte b;
|
|
|
|
b = elements[byteIndexForBit(bit)];
|
|
b &= ~(1 << bitIndexWithinByte(bit));
|
|
elements[byteIndexForBit(bit)] = b;
|
|
}
|
|
|
|
public static int byteIndexForBit(int bit) {
|
|
return bit / BITS_PER_BYTE;
|
|
}
|
|
|
|
public static int bitIndexWithinByte(int bit) {
|
|
return bit % BITS_PER_BYTE;
|
|
}
|
|
}
|
|
|