Skip to content

Commit daa4135

Browse files
committed
Add method documentation to HAPBS
1 parent f2890c5 commit daa4135

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

core/src/main/java/org/neo4j/gds/core/utils/paged/HugeAtomicPagedBitSet.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ private HugeAtomicPagedBitSet(int pageCount, int pageSize, int pageShift, long p
6969
this.pages = new AtomicReference<>(new Pages(pageCount, pageSize));
7070
}
7171

72+
/**
73+
* Sets the bit at the given index to true.
74+
*/
7275
public void set(long index) {
7376
long longIndex = index >>> 6;
7477
int pageIndex = HugeArrays.pageIndex(longIndex, pageShift);
@@ -95,6 +98,9 @@ public void set(long index) {
9598
}
9699
}
97100

101+
/**
102+
* Returns the state of the bit at the given index.
103+
*/
98104
public boolean get(long index) {
99105
long longIndex = index >>> 6;
100106
int pageIndex = HugeArrays.pageIndex(longIndex, pageShift);
@@ -106,6 +112,10 @@ public boolean get(long index) {
106112
return (page.get(wordIndex) & bitMask) != 0;
107113
}
108114

115+
/**
116+
* Sets a bit and returns the previous value.
117+
* The index should be less than the BitSet size.
118+
*/
109119
public boolean getAndSet(long index) {
110120
long longIndex = index >>> 6;
111121
int pageIndex = HugeArrays.pageIndex(longIndex, pageShift);
@@ -132,6 +142,13 @@ public boolean getAndSet(long index) {
132142
}
133143
}
134144

145+
/**
146+
* Returns the number of set bits in the bit set.
147+
* <p>
148+
* The result of the method does not include the effects
149+
* of concurrent write operations that occur while the
150+
* cardinality is computed.
151+
*/
135152
public long cardinality() {
136153
final Pages pages = this.pages.get();
137154
final long pageCount = pages.length();
@@ -150,6 +167,14 @@ public long cardinality() {
150167
return setBitCount;
151168
}
152169

170+
/**
171+
* Iterates the bit set in increasing index order and calls the
172+
* given consumer for each index with a set bit.
173+
* <p>
174+
* The result of the method does not include the effects
175+
* of concurrent write operations that occur while the
176+
* bit set if traversed.
177+
*/
153178
public void forEachSetBit(LongConsumer consumer) {
154179
final Pages pages = this.pages.get();
155180
final long pageCount = pages.length();
@@ -172,6 +197,9 @@ public void forEachSetBit(LongConsumer consumer) {
172197
}
173198
}
174199

200+
/**
201+
* Resets the bit at the given index.
202+
*/
175203
public void clear(long index) {
176204
long longIndex = index >>> 6;
177205
int pageIndex = HugeArrays.pageIndex(longIndex, pageShift);
@@ -198,10 +226,20 @@ public void clear(long index) {
198226
}
199227
}
200228

229+
/**
230+
* The current capacity of the bit set. Setting a bit at an index
231+
* exceeding the capacity, leads to a resize operation.
232+
* The cardinality is a multiple of the underling page size:
233+
* 2^{@link org.neo4j.gds.core.utils.paged.HugeAtomicPagedBitSet#PAGE_SHIFT_BITS}.
234+
*/
201235
public long capacity() {
202236
return pages.get().length() * (1L << pageShift);
203237
}
204238

239+
/**
240+
* Returns the page at the given index, potentially growing the underlying pages
241+
* to fit the requested page index.
242+
*/
205243
private AtomicLongArray getPage(int pageIndex) {
206244
var pages = this.pages.get();
207245

0 commit comments

Comments
 (0)