FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mercury/java/runtime/MercuryBitmap.java at master · Mercury-Language/mercury · GitHub
Mercury-Language
/
mercury
Public
Notifications
You must be signed in to change notification settings
Fork
71
Star
1.1k
Code
Issues
13
Pull requests
8
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
mercury
/
java
/
runtime
/
MercuryBitmap.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
72 lines (60 loc) · 1.94 KB
Breadcrumbs
mercury
/
java
/
runtime
/
MercuryBitmap.java
Copy path
File metadata and controls
72 lines (60 loc) · 1.94 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// vim: ts=4 sw=4 expandtab ft=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
;
}
}
Back
|
FazBrowse Home
|
New Git URL