Skip to main content

BitSet

Struct BitSet 

Source
pub struct BitSet { /* private fields */ }
Expand description

A variable-length bit array encoded as a VarInt-prefixed array of i64 values.

BitSet is used in the Minecraft protocol for chunk light masks, section bitmasks, and other bitfield data where an arbitrary number of boolean flags need to be packed efficiently. Each i64 holds 64 bits, and the array grows as needed to accommodate the highest set bit.

Wire format: VarInt(number of longs) followed by that many big-endian i64 values. An empty BitSet has zero longs.

Implementations§

Source§

impl BitSet

Source

pub fn new() -> Self

Creates a new empty BitSet with no bits set.

Source

pub fn from_longs(data: Vec<i64>) -> Self

Creates a BitSet from a pre-existing vector of i64 words.

Each i64 holds 64 bits. The first element contains bits 0-63, the second 64-127, and so on. This is useful when constructing a BitSet from data received outside the protocol decoding path.

Source

pub fn len(&self) -> usize

Returns the number of bits this BitSet can currently hold without growing (i.e., the number of longs × 64).

Source

pub fn is_empty(&self) -> bool

Returns true if the BitSet contains no longs (zero capacity).

Source

pub fn get(&self, index: usize) -> bool

Returns the value of the bit at the given index.

Returns false for indices beyond the current capacity — bits outside the allocated range are implicitly zero.

Source

pub fn set(&mut self, index: usize, value: bool)

Sets or clears the bit at the given index.

If the index is beyond the current capacity and value is true, the internal storage is automatically extended with zero-filled longs. Setting a bit to false beyond the current capacity is a no-op (the bit is already implicitly zero).

Trait Implementations§

Source§

impl Clone for BitSet

Source§

fn clone(&self) -> BitSet

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BitSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Decode for BitSet

Decodes a BitSet from a VarInt-prefixed array of big-endian i64 values.

Reads the VarInt count, then that many 8-byte big-endian i64 values. Fails if the buffer doesn’t contain enough bytes for the declared number of longs.

Source§

fn decode(buf: &mut &[u8]) -> Result<Self>

Reads the VarInt length, then decodes that many i64 words.

Fails with Error::BufferUnderflow if the buffer is too short, or with Error::InvalidData if the declared length is negative.

Source§

impl Default for BitSet

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Encode for BitSet

Encodes the BitSet as a VarInt-prefixed array of big-endian i64 values.

The VarInt indicates the number of longs in the array, followed by each long encoded as 8 big-endian bytes. An empty BitSet encodes as a single VarInt(0) byte.

Source§

fn encode(&self, buf: &mut Vec<u8>) -> Result<()>

Writes VarInt(number of longs) followed by each long as 8 big-endian bytes.

Source§

impl EncodedSize for BitSet

Computes the wire size of the BitSet.

The total size is the VarInt-encoded length prefix plus 8 bytes per long. This enables exact buffer pre-allocation before encoding.

Source§

fn encoded_size(&self) -> usize

Returns VarInt prefix size + (number of longs × 8).

Source§

impl Hash for BitSet

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for BitSet

Source§

fn eq(&self, other: &BitSet) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for BitSet

Source§

impl StructuralPartialEq for BitSet

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.