-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Changes to build star tree in off heap #14817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sachinpkale
merged 11 commits into
opensearch-project:main
from
bharath-techie:off_heap_star_tree
Aug 7, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b9d72e0
Off heap changes for star tree
bharath-techie 4ec529f
addressing review comments
bharath-techie 725e8f0
Merge branch 'main' of github.com:opensearch-project/OpenSearch into …
bharath-techie 91be29b
Addressing comments
bharath-techie 14bd5e6
Modularizing the code
bharath-techie 62d9e31
Addressing comments and correcting close files
bharath-techie dccc30e
addressing review comments
bharath-techie ce062ec
Merge branch 'main' of github.com:opensearch-project/OpenSearch into …
bharath-techie 3dfc384
Merge branch 'main' of github.com:opensearch-project/OpenSearch into …
bharath-techie 7f637c7
addressing comments
bharath-techie 8d50c39
Merge branch 'main' of github.com:opensearch-project/OpenSearch into …
bharath-techie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 { | ||
sachinpkale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.