diff options
| author | mat <git@matdoes.dev> | 2025-02-23 17:39:17 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-02-23 17:39:17 +0000 |
| commit | 6a5ab34a2db56c22e1051dfaabf98322c50f53bd (patch) | |
| tree | bf0e13174c5bbb2bc6885ea357683a030aff5465 /azalea-world/src/bit_storage.rs | |
| parent | 2be4f0f2b66eb7181badec0134c3c3565e3cbd7f (diff) | |
| download | azalea-drasl-6a5ab34a2db56c22e1051dfaabf98322c50f53bd.tar.xz | |
azalea-language now does a binary search instead of a hashmap lookup
Diffstat (limited to 'azalea-world/src/bit_storage.rs')
| -rwxr-xr-x | azalea-world/src/bit_storage.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/azalea-world/src/bit_storage.rs b/azalea-world/src/bit_storage.rs index 1b0c1a56..7d1b72e1 100755 --- a/azalea-world/src/bit_storage.rs +++ b/azalea-world/src/bit_storage.rs @@ -101,7 +101,11 @@ impl Error for BitStorageError {} impl BitStorage { /// Create a new BitStorage with the given number of bits per entry. /// `size` is the number of entries in the BitStorage. - pub fn new(bits: usize, size: usize, data: Option<Vec<u64>>) -> Result<Self, BitStorageError> { + pub fn new( + bits: usize, + size: usize, + data: Option<Box<[u64]>>, + ) -> Result<Self, BitStorageError> { if let Some(data) = &data { // 0 bit storage if data.is_empty() { @@ -132,11 +136,11 @@ impl BitStorage { } data } else { - vec![0; calculated_length] + vec![0; calculated_length].into() }; Ok(BitStorage { - data: using_data.into(), + data: using_data, bits, mask, size, @@ -252,7 +256,7 @@ mod tests { 1, 2, 2, 3, 4, 4, 5, 6, 6, 4, 8, 0, 7, 4, 3, 13, 15, 16, 9, 14, 10, 12, 0, 2, ]; let compact_data: [u64; 2] = [0x0020863148418841, 0x01018A7260F68C87]; - let storage = BitStorage::new(5, data.len(), Some(compact_data.to_vec())).unwrap(); + let storage = BitStorage::new(5, data.len(), Some(Box::new(compact_data))).unwrap(); for (i, expected) in data.iter().enumerate() { assert_eq!(storage.get(i), *expected); |
