From 4247945df13507fb07a4746263bb702d6fbe04cd Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 18 Sep 2022 23:13:45 -0500 Subject: start work on optimizing block macros --- azalea-core/src/bitset.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'azalea-core/src') diff --git a/azalea-core/src/bitset.rs b/azalea-core/src/bitset.rs index 2ffd5657..6f0a27ca 100644 --- a/azalea-core/src/bitset.rs +++ b/azalea-core/src/bitset.rs @@ -7,6 +7,8 @@ pub struct BitSet { data: Vec, } +const ADDRESS_BITS_PER_WORD: usize = 6; + // the Index trait requires us to return a reference, but we can't do that impl BitSet { pub fn new(size: usize) -> Self { @@ -18,6 +20,54 @@ impl BitSet { pub fn index(&self, index: usize) -> bool { (self.data[index / 64] & (1u64 << (index % 64))) != 0 } + + // private static int wordIndex(int bitIndex) { + // return bitIndex >> ADDRESS_BITS_PER_WORD; + // } + pub fn word_index(bit_index: usize) -> usize { + bit_index >> ADDRESS_BITS_PER_WORD + } + + pub fn clear_from_to(&mut self, from: usize, to: usize) { + assert!(from <= to); + assert!(to <= self.data.len() * 64); + assert!(to > 0); + + if from == to { + return; + } + + // int startWordIndex = wordIndex(fromIndex); + // if (startWordIndex >= wordsInUse) + // return; + + // int endWordIndex = wordIndex(toIndex - 1); + // if (endWordIndex >= wordsInUse) { + // toIndex = length(); + // endWordIndex = wordsInUse - 1; + // } + + // long firstWordMask = WORD_MASK << fromIndex; + // long lastWordMask = WORD_MASK >>> -toIndex; + // if (startWordIndex == endWordIndex) { + // // Case 1: One word + // words[startWordIndex] &= ~(firstWordMask & lastWordMask); + // } else { + // // Case 2: Multiple words + // // Handle first word + // words[startWordIndex] &= ~firstWordMask; + + // // Handle intermediate words, if any + // for (int i = startWordIndex+1; i < endWordIndex; i++) + // words[i] = 0; + + // // Handle last word + // words[endWordIndex] &= ~lastWordMask; + // } + + // recalculateWordsInUse(); + // checkInvariants(); + } } impl McBufReadable for BitSet { -- cgit v1.2.3