forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add changes to build star tree in off heap (opensearch-project#14817)
--------- Signed-off-by: Bharathwaj G <[email protected]>
- Loading branch information
1 parent
e136f46
commit dd4362e
Showing
24 changed files
with
2,028 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
server/src/main/java/org/opensearch/common/util/ByteArrayBackedBitset.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.util; | ||
|
||
import org.apache.lucene.store.IndexInput; | ||
import org.apache.lucene.store.IndexOutput; | ||
import org.apache.lucene.store.RandomAccessInput; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* A bitset backed by a byte array. This will initialize and set bits in the byte array based on the index. | ||
*/ | ||
public class ByteArrayBackedBitset { | ||
private final byte[] byteArray; | ||
|
||
/** | ||
* Constructor which uses an on heap list. This should be using during construction of the bitset. | ||
*/ | ||
public ByteArrayBackedBitset(int capacity) { | ||
byteArray = new byte[capacity]; | ||
} | ||
|
||
/** | ||
* Constructor which set the Lucene's RandomAccessInput to read the bitset into a read-only buffer. | ||
*/ | ||
public ByteArrayBackedBitset(RandomAccessInput in, long offset, int length) throws IOException { | ||
byteArray = new byte[length]; | ||
int i = 0; | ||
while (i < length) { | ||
byteArray[i] = in.readByte(offset + i); | ||
i++; | ||
} | ||
} | ||
|
||
/** | ||
* Constructor which set the Lucene's IndexInput to read the bitset into a read-only buffer. | ||
*/ | ||
public ByteArrayBackedBitset(IndexInput in, int length) throws IOException { | ||
byteArray = new byte[length]; | ||
int i = 0; | ||
while (i < length) { | ||
byteArray[i] = in.readByte(); | ||
i++; | ||
} | ||
} | ||
|
||
/** | ||
* Sets the bit at the given index to 1. | ||
* Each byte can indicate 8 bits, so the index is divided by 8 to get the byte array index. | ||
* @param index the index to set the bit | ||
*/ | ||
public void set(int index) { | ||
int byteArrIndex = index >> 3; | ||
byteArray[byteArrIndex] |= (byte) (1 << (index & 7)); | ||
} | ||
|
||
public int write(IndexOutput output) throws IOException { | ||
int numBytes = 0; | ||
for (Byte bitSet : byteArray) { | ||
output.writeByte(bitSet); | ||
numBytes += Byte.BYTES; | ||
} | ||
return numBytes; | ||
} | ||
|
||
/** | ||
* Retrieves whether the bit is set or not at the given index. | ||
* @param index the index to look up for the bit | ||
* @return true if bit is set, false otherwise | ||
*/ | ||
public boolean get(int index) throws IOException { | ||
int byteArrIndex = index >> 3; | ||
return (byteArray[byteArrIndex] & (1 << (index & 7))) != 0; | ||
} | ||
|
||
public int getCurrBytesRead() { | ||
return byteArray.length; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.