aboutsummaryrefslogtreecommitdiff
path: root/azalea-world/src/bit_storage.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-08 23:45:15 -0500
committermat <github@matdoes.dev>2022-05-08 23:45:15 -0500
commit345cecf7afa84df2d5ecf075ecfb499e3fd10a55 (patch)
tree4657aebf820aab0e934cc501fcbb822d5ef2c84f /azalea-world/src/bit_storage.rs
parent122693a654b0c851bbb9e134c539961419175bef (diff)
downloadazalea-drasl-345cecf7afa84df2d5ecf075ecfb499e3fd10a55.tar.xz
add more stuff
Diffstat (limited to 'azalea-world/src/bit_storage.rs')
-rw-r--r--azalea-world/src/bit_storage.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/azalea-world/src/bit_storage.rs b/azalea-world/src/bit_storage.rs
index 9cc3a053..211a4a04 100644
--- a/azalea-world/src/bit_storage.rs
+++ b/azalea-world/src/bit_storage.rs
@@ -70,9 +70,9 @@ const MAGIC: [(i32, i32, i32); 64] = [
];
/// A compact list of integers with the given number of bits per entry.
-#[derive(Clone)]
+#[derive(Clone, Debug, Default)]
pub struct BitStorage {
- data: Vec<u64>,
+ pub data: Vec<u64>,
bits: usize,
mask: u64,
size: usize,
@@ -103,9 +103,17 @@ 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> {
+ if let Some(data) = &data {
+ if data.len() == 0 {
+ // TODO: make 0 bit storage actually work
+ return Ok(BitStorage::default());
+ }
+ }
+
let values_per_long = 64 / bits;
let magic_index = values_per_long - 1;
let (divide_mul, divide_add, divide_shift) = MAGIC[magic_index as usize];
+ println!("values_per_long: {}, size: {}", values_per_long, size);
let calculated_length = (size + values_per_long - 1) / values_per_long;
let mask = (1 << bits) - 1;