| { | ||
| "git": { | ||
| "sha1": "d3972402c9e8997962e6b1b39ab1306b0cce46df" | ||
| "sha1": "c969650940bd037acfe5238e20a4b9ff6dcde057" | ||
| } | ||
| } |
+1
-1
@@ -5,3 +5,3 @@ # This file is automatically @generated by Cargo. | ||
| name = "bitvec" | ||
| version = "0.18.1" | ||
| version = "0.18.3" | ||
| dependencies = [ | ||
@@ -8,0 +8,0 @@ "funty 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", |
+1
-1
@@ -16,3 +16,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| name = "bitvec" | ||
| version = "0.18.1" | ||
| version = "0.18.3" | ||
| authors = ["myrrlyn <self@myrrlyn.dev>"] | ||
@@ -19,0 +19,0 @@ include = ["Cargo.toml", "src/**/*.rs"] |
+6
-3
@@ -27,3 +27,6 @@ /*! Memory access control. | ||
| use radium::Radium; | ||
| use radium::{ | ||
| marker::BitOps, | ||
| Radium, | ||
| }; | ||
@@ -41,3 +44,3 @@ /** Access interface to memory locations. | ||
| pub trait BitAccess<M>: Debug + Radium<M> + Sized | ||
| where M: BitMemory | ||
| where M: BitMemory + BitOps | ||
| { | ||
@@ -359,3 +362,3 @@ /// Sets one bit in a memory element to `0`. | ||
| where | ||
| M: BitMemory, | ||
| M: BitMemory + BitOps, | ||
| R: Debug + Radium<M>, | ||
@@ -362,0 +365,0 @@ { |
+44
-13
@@ -51,3 +51,6 @@ /*! A dynamically-allocated, fixed-size, buffer containing a `BitSlice` region. | ||
| use wyz::pipe::Pipe; | ||
| use wyz::pipe::{ | ||
| Pipe, | ||
| PipeRef, | ||
| }; | ||
@@ -381,3 +384,40 @@ /** A frozen heap-allocated buffer of individual bits. | ||
| /// Sets the uninitialized bits of the vector to a fixed value. | ||
| /// | ||
| /// This method modifies all bits in the allocated buffer that are outside | ||
| /// the `self.as_bitslice()` view so that they have a consistent value. This | ||
| /// can be used to zero the uninitialized memory so that when viewed as a | ||
| /// raw memory slice, bits outside the live region have a predictable value. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ```rust | ||
| /// use bitvec::prelude::*; | ||
| /// | ||
| /// let mut bb = BitBox::new(&220u8.view_bits::<Lsb0>()[.. 4]); | ||
| /// assert_eq!(bb.count_ones(), 2); | ||
| /// assert_eq!(bb.as_slice(), &[220u8]); | ||
| /// | ||
| /// bb.set_uninitialized(false); | ||
| /// assert_eq!(bb.as_slice(), &[12u8]); | ||
| /// | ||
| /// bb.set_uninitialized(true); | ||
| /// assert_eq!(bb.as_slice(), &[!3u8]); | ||
| /// ``` | ||
| #[inline] | ||
| pub fn set_uninitialized(&mut self, value: bool) { | ||
| let head = self.bitptr().head().value() as usize; | ||
| let tail = head + self.len(); | ||
| let elts = self.bitptr().elements() * T::Mem::BITS as usize; | ||
| let mut bp = self.bitptr(); | ||
| unsafe { | ||
| bp.set_head(BitIdx::ZERO); | ||
| bp.set_len(elts); | ||
| let bits = bp.to_bitslice_mut::<O>(); | ||
| bits.get_unchecked_mut(.. head).set_all(value); | ||
| bits.get_unchecked_mut(tail ..).set_all(value); | ||
| } | ||
| } | ||
| #[inline] | ||
| pub(crate) fn bitptr(&self) -> BitPtr<T> { | ||
@@ -412,16 +452,7 @@ self.pointer.as_ptr().pipe(BitPtr::from_bitslice_ptr_mut) | ||
| where F: FnOnce(&mut ManuallyDrop<Box<[T::Mem]>>) -> R { | ||
| let mut bitptr = self.bitptr(); | ||
| let mut boxed = self | ||
| .as_mut_slice() | ||
| self.as_mut_slice() | ||
| .pipe(|s| s as *mut [T] as *mut [T::Mem]) | ||
| .pipe(|raw| unsafe { Box::from_raw(raw) }) | ||
| .pipe(ManuallyDrop::new); | ||
| let out = func(&mut boxed); | ||
| unsafe { | ||
| bitptr.set_pointer(boxed.as_ptr() as *mut T); | ||
| } | ||
| self.pointer = bitptr.to_nonnull(); | ||
| out | ||
| .pipe(ManuallyDrop::new) | ||
| .pipe_mut(func) | ||
| } | ||
@@ -428,0 +459,0 @@ } |
@@ -24,2 +24,11 @@ //! Unit tests for the `boxed` module. | ||
| assert_eq!(bb.bitptr(), bitptr); | ||
| let mut bb = 0b1001_0110u8.view_bits::<Msb0>()[2 .. 6] | ||
| .to_bitvec() | ||
| .into_boxed_bitslice(); | ||
| bb.set_uninitialized(false); | ||
| assert_eq!(bb.as_slice(), &[0b0001_0100]); | ||
| bb.set_uninitialized(true); | ||
| assert_eq!(bb.as_slice(), &[0b1101_0111]); | ||
| assert_eq!(bb, bits![0, 1, 0, 1]); | ||
| } |
@@ -131,2 +131,10 @@ //! Tests for the `field` module. | ||
| #[test] | ||
| fn wide_load() { | ||
| let mut data = bitarr![Lsb0, u16; 0; 256]; | ||
| assert_eq!(data[16 .. 144].load::<u128>(), 0u128); | ||
| data[16 .. 144].store(!0u128); | ||
| assert_eq!(data[16 .. 144].load::<u128>(), !0u128); | ||
| } | ||
| #[test] | ||
| #[should_panic] | ||
@@ -133,0 +141,0 @@ fn check_panic() { |
+6
-6
@@ -93,3 +93,3 @@ //! Constructor macros for the crate’s collection types. | ||
| (mut $($val:expr),* $(,)?) => { | ||
| unsafe { $crate::bits!(mut LocalBits, usize; $($val),*) } | ||
| unsafe { $crate::bits!(mut Lsb0, usize; $($val),*) } | ||
| }; | ||
@@ -135,3 +135,3 @@ | ||
| (mut $val:expr; $len:expr) => { | ||
| $crate::bits!(mut LocalBits, usize; $val; $len) | ||
| $crate::bits!(mut Lsb0, usize; $val; $len) | ||
| }; | ||
@@ -170,3 +170,3 @@ | ||
| ($($val:expr),* $(,)?) => { | ||
| $crate::bits!(LocalBits, usize; $($val),*) | ||
| $crate::bits!(Lsb0, usize; $($val),*) | ||
| }; | ||
@@ -199,3 +199,3 @@ | ||
| ($val:expr; $len:expr) => { | ||
| $crate::bits!(LocalBits, usize; $val; $len) | ||
| $crate::bits!(Lsb0, usize; $val; $len) | ||
| }; | ||
@@ -299,3 +299,3 @@ } | ||
| ($($val:expr),* $(,)?) => { | ||
| $crate::bitarr!(LocalBits, usize; $($val),*) | ||
| $crate::bitarr!(Lsb0, usize; $($val),*) | ||
| }; | ||
@@ -324,3 +324,3 @@ | ||
| ($val:expr; $len:expr) => { | ||
| $crate::bitarr!(LocalBits, usize; $val; $len) | ||
| $crate::bitarr!(Lsb0, usize; $val; $len) | ||
| }; | ||
@@ -327,0 +327,0 @@ } |
+29
-17
@@ -1,6 +0,6 @@ | ||
| /*! Descriptions of register types | ||
| /*! Descriptions of integer types | ||
| This module describes the register types used to hold bare data. This module | ||
| governs the way the processor manipulates values held in registers, without | ||
| concern for interaction with memory locations. | ||
| This module describes the integer types used to hold bare data. This module | ||
| governs the way the processor manipulates integer regions of memory, without | ||
| concern for interaction with specifics of register or bus behavior. | ||
| !*/ | ||
@@ -12,15 +12,13 @@ | ||
| use radium::marker::BitOps; | ||
| /** Description of an integer type. | ||
| /** Description of a register type. | ||
| This trait provides information used to describe integer-typed regions of memory | ||
| and enables other parts of the crate to adequately describe the memory bus. This | ||
| trait has **no** bearing on the processor instructions or registers used to | ||
| interact with memory. | ||
| This trait provides information used for the manipulation of values in processor | ||
| registers, and the computation of the state of system memory. It has no bearing | ||
| on the behavior used to perform loads or stores between the processor and the | ||
| memory bus. | ||
| This trait cannot be implemented outside this crate. | ||
| **/ | ||
| pub trait BitMemory: IsUnsigned + BitOps + seal::Sealed { | ||
| /// The bit width of the register element. | ||
| pub trait BitMemory: IsUnsigned + seal::Sealed { | ||
| /// The bit width of the integer. | ||
| /// | ||
@@ -51,7 +49,4 @@ /// `mem::size_of` returns the size in bytes, and bytes are always eight | ||
| memory!(u8, u16, u32, usize); | ||
| memory!(u8, u16, u32, u64, u128, usize); | ||
| #[cfg(target_pointer_width = "64")] | ||
| memory!(u64); | ||
| /** Computes the number of elements required to store some number of bits. | ||
@@ -95,2 +90,19 @@ | ||
| /** Tests whether two types have compatible layouts. | ||
| # Type Parameters | ||
| - `A` | ||
| - `B` | ||
| # Returns | ||
| Zero if `A` and `B` have equal alignments and sizes, non-zero if they do not. | ||
| # Uses | ||
| This function is designed to be used in the expression | ||
| `const CHECK: [(): 0] = [(); cmp_layout::<A, B>()];`. It will cause a compiler | ||
| error if the conditions do not hold. | ||
| **/ | ||
| #[doc(hidden)] | ||
@@ -97,0 +109,0 @@ pub(crate) const fn cmp_layout<A, B>() -> usize { |
+16
-7
@@ -20,3 +20,6 @@ /*! Memory modeling. | ||
| use radium::Radium; | ||
| use radium::{ | ||
| marker::BitOps, | ||
| Radium, | ||
| }; | ||
@@ -28,7 +31,13 @@ #[cfg(feature = "atomic")] | ||
| This trait is implemented on the fundamental integers, their `Cell` wrappers, | ||
| and (if present) their `Atomic` variants. Users provide this type as a parameter | ||
| to their data structures in order to inform the structure of how it may access | ||
| the memory it describes. | ||
| This trait is implemented on the fundamental integers no wider than the target | ||
| processor word size, their `Cell` wrappers, and (if present) their `Atomic` | ||
| variants. Users provide this type as a parameter to their data structures in | ||
| order to inform the structure of how it may access the memory it describes. | ||
| Currently, `bitvec` is only tested on 32- and 64- bit architectures. This means | ||
| that `u8`, `u16`, `u32`, and `usize` unconditionally implement `BitStore`, but | ||
| `u64` will only do so on 64-bit targets, and will be unavailable on 32-bit | ||
| targets. This is a necessary restriction of `bitvec` internals. Please comment | ||
| on [Issue #76](https://github.com/myrrlyn/bitvec/issues/76) if this affects you. | ||
| Specifically, this has the davantage that a `BitSlice<_, Cell<_>>` knows that it | ||
@@ -80,3 +89,3 @@ has a view of memory that will not undergo concurrent modification. As such, it | ||
| /// The register type that the implementor describes. | ||
| type Mem: BitMemory + Into<Self> + BitStore; | ||
| type Mem: BitMemory + BitOps + BitStore + Into<Self>; | ||
@@ -186,3 +195,3 @@ /// The modifier type over `Self::Mem` used to perform memory access. | ||
| Self: Radium<M>, | ||
| M: BitMemory + BitStore, | ||
| M: BitMemory + BitOps + BitStore, | ||
| { | ||
@@ -189,0 +198,0 @@ type Access = Self; |
+39
-0
@@ -414,2 +414,41 @@ /*! A dynamically-allocated buffer containing a `BitSlice<O, T>` region. | ||
| /// Sets the uninitialized bits of the vector to a fixed value. | ||
| /// | ||
| /// This method modifies all bits in the allocated buffer that are outside | ||
| /// the `self.as_bitslice()` view so that they have a consistent value. This | ||
| /// can be used to zero the uninitialized memory so that when viewed as a | ||
| /// raw memory slice, bits outside the live region have a predictable value. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ```rust | ||
| /// use bitvec::prelude::*; | ||
| /// | ||
| /// let mut bv = 220u8.view_bits::<Lsb0>().to_bitvec(); | ||
| /// assert_eq!(bv.as_slice(), &[220u8]); | ||
| /// bv.truncate(4); | ||
| /// assert_eq!(bv.count_ones(), 2); | ||
| /// assert_eq!(bv.as_slice(), &[220u8]); | ||
| /// | ||
| /// bv.set_uninitialized(false); | ||
| /// assert_eq!(bv.as_slice(), &[12u8]); | ||
| /// | ||
| /// bv.set_uninitialized(true); | ||
| /// assert_eq!(bv.as_slice(), &[!3u8]); | ||
| /// ``` | ||
| #[inline] | ||
| pub fn set_uninitialized(&mut self, value: bool) { | ||
| let head = self.bitptr().head().value() as usize; | ||
| let tail = head + self.len(); | ||
| let capa = self.capacity(); | ||
| let mut bp = self.bitptr(); | ||
| unsafe { | ||
| bp.set_head(BitIdx::ZERO); | ||
| bp.set_len(capa); | ||
| let bits = bp.to_bitslice_mut::<O>(); | ||
| bits.get_unchecked_mut(.. head).set_all(value); | ||
| bits.get_unchecked_mut(tail ..).set_all(value); | ||
| } | ||
| } | ||
| /// Ensures that the live region of the vector’s contents begins at the | ||
@@ -416,0 +455,0 @@ /// leading edge of the buffer. |
+10
-4
@@ -273,4 +273,4 @@ //! Port of the `Vec<T>` function API. | ||
| pub fn reserve(&mut self, additional: usize) { | ||
| let new_len = self | ||
| .len() | ||
| let len = self.len(); | ||
| let new_len = len | ||
| .checked_add(additional) | ||
@@ -290,2 +290,5 @@ .expect("Vector capacity exceeded"); | ||
| self.with_vec(|v| v.reserve(extra)); | ||
| let capa = self.capacity(); | ||
| // Zero the newly-reserved buffer. | ||
| unsafe { self.get_unchecked_mut(len .. capa) }.set_all(false); | ||
| } | ||
@@ -418,3 +421,5 @@ } | ||
| /// Note that this method has no effect on the allocated capacity of the | ||
| /// vector. | ||
| /// vector, **nor does it erase truncated memory**. Bits in the allocated | ||
| /// memory that are outside of the `.as_bitslice()` view always have | ||
| /// **unspecified** values, and cannot be relied upon to be zero. | ||
| /// | ||
@@ -435,2 +440,3 @@ /// # Original | ||
| /// assert_eq!(bv.len(), 2); | ||
| /// assert!(bv.as_slice()[0].count_ones() >= 5); | ||
| /// ``` | ||
@@ -449,3 +455,3 @@ /// | ||
| /// | ||
| /// Truncating when `len == 0` is equivalent to calling the [`clean`] | ||
| /// Truncating when `len == 0` is equivalent to calling the [`clear`] | ||
| /// method. | ||
@@ -452,0 +458,0 @@ /// |
+8
-1
@@ -44,3 +44,3 @@ #![cfg(test)] | ||
| #[test] | ||
| fn force_align() { | ||
| fn buffer_control() { | ||
| let data = 0xA5u8; | ||
@@ -55,2 +55,9 @@ let bits = data.view_bits::<Msb0>(); | ||
| assert_eq!(bv.as_slice(), &[0b1001_0101]); | ||
| bv.truncate(6); | ||
| bv.set_uninitialized(false); | ||
| assert_eq!(bv.as_slice(), &[0b1001_0100]); | ||
| bv.set_uninitialized(true); | ||
| assert_eq!(bv.as_slice(), &[0b1001_0111]); | ||
| assert_eq!(bv, bits![1, 0, 0, 1, 0, 1]); | ||
| } | ||
@@ -57,0 +64,0 @@ |
+1
-1
@@ -228,3 +228,3 @@ /*! View constructors for memory regions. | ||
| BitPtr::new_unchecked( | ||
| self.as_ptr(), | ||
| self.as_mut_ptr(), | ||
| BitIdx::ZERO, | ||
@@ -231,0 +231,0 @@ $n * T::Mem::BITS as usize, |
Sorry, the diff of this file is not supported yet