Expand description
A library for working with custom aligned buffers of sized values.
The vortex-buffer crate is built around bytes::Bytes and therefore supports zero-copy
cloning and slicing, but differs in that it can define and maintain a custom alignment.
Buffer<T>andBufferMut<T>provide immutable and mutable wrappers aroundbytes::Bytesandbytes::BytesMutrespectively.ByteBufferandByteBufferMutare type aliases foru8buffers.BufferStringis a wrapper around aByteBufferthat enforces utf-8 encoding.ConstBuffer<T, const A: usize>provides similar functionality toBuffer<T>except with a compile-time alignment ofA.buffer!andbuffer_mut!macros with the same syntax as the builtinvec!macro for inline construction of buffers.
You can think of BufferMut<T> as similar to a Vec<T>, except that any operation that may
cause a re-allocation, e.g. extend, will ensure the new allocation maintains the buffer’s
defined alignment.
For example, it’s possible to incrementally build a Buffer<T> with a 4KB alignment.
use vortex_buffer::{Alignment, BufferMut};
let mut buf = BufferMut::<i32>::empty_aligned(Alignment::new(4096));
buf.extend(0i32..1_000);
assert_eq!(buf.as_ptr().align_offset(4096), 0)§Comparison
| Implementation | Zero-copy | Custom Alignment | Typed |
|---|---|---|---|
vortex_buffer::Buffer<T> | ✔️ | ✔️ | ✔️ |
arrow_buffer::ScalarBuffer<T> | ✔️ | ❌️️️ | ✔️ |
bytes::Bytes | ✔️ | ❌️️️ | ❌️️️ |
Vec<T> | ❌️ | ❌️️ | ✔️ |
§Features
The arrow feature can be enabled to provide conversion functions to/from Arrow Rust buffers,
including arrow_buffer::Buffer, arrow_buffer::ScalarBuffer<T>, and
arrow_buffer::OffsetBuffer.
Macros§
- bitbuffer
- A macro for constructing bit-buffers akin to
vec![..]. - bitbuffer_
mut - A macro for constructing bit-buffers akin to
vec![..]. - buffer
- A macro for constructing buffers akin to
vec![..]. - buffer_
mut - A macro for constructing buffers akin to
vec![..].
Structs§
- Alignment
- The alignment of a buffer.
- BitBuffer
- An immutable bitset stored as a packed byte buffer.
- BitBuffer
Mut - A mutable bitset buffer that allows random access to individual bits for set and get.
- BitChunk
Iterator - Iterator over chunks of 64 bits represented as an u64
- BitChunks
- Iterates over an arbitrarily aligned byte buffer
- BitIndex
Iterator - An iterator of
usizewhose index in a provided bitmask is true - BitIterator
- Iterator over the bits within a packed bitmask
- BitSlice
Iterator - Iterator of contiguous ranges of set bits within a provided packed bitmask
- Buffer
- An immutable buffer of items of
T. - Buffer
Iterator - Owned iterator over a
Buffer. - Buffer
Mut - A mutable buffer that maintains a runtime-defined alignment through resizing operations.
- Buffer
String - A wrapper around a
ByteBufferthat guarantees that the buffer contains valid UTF-8. - Const
Buffer - A buffer of items of
Twith a compile-time alignment. - Iter
- An iterator over Buffer elements.
- Unaligned
BitChunk - Iterates over an arbitrarily aligned byte buffer
Traits§
- Aligned
Buf - An extension to the
Buftrait that provides a functioncopy_to_alignedsimilar tocopy_to_bytesthat allows for zero-copy aligned reads where possible.
Type Aliases§
- Byte
Buffer - An immutable buffer of u8.
- Byte
Buffer Mut - A mutable buffer of u8.
- Const
Byte Buffer - A const-aligned buffer of u8.
- Unaligned
BitChunk Iterator - Iterator over an
UnalignedBitChunk