Skip to content

Commit c245a45

Browse files
authored
Minor: Clarify documentation on NullBufferBuilder::allocated_size (#7089)
* Minor: Clarify documentaiton on NullBufferBuilder::allocated_size * add note about why allocations are 64 bytes
1 parent 91aa6fd commit c245a45

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

arrow-buffer/src/buffer/mutable.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ impl MutableBuffer {
288288
self.len
289289
}
290290

291-
/// Returns the total capacity in this buffer.
291+
/// Returns the total capacity in this buffer, in bytes.
292+
///
292293
/// The invariant `buffer.len() <= buffer.capacity()` is always upheld.
293294
#[inline]
294295
pub const fn capacity(&self) -> usize {

arrow-buffer/src/builder/boolean.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,24 @@ impl BooleanBufferBuilder {
8383
self.len == 0
8484
}
8585

86-
/// Returns the capacity of the buffer
86+
/// Returns the capacity of the buffer, in bits (not bytes)
87+
///
88+
/// Note this
89+
///
90+
/// # Example
91+
/// ```
92+
/// # use arrow_buffer::builder::BooleanBufferBuilder;
93+
/// // empty requires 0 bytes
94+
/// let b = BooleanBufferBuilder::new(0);
95+
/// assert_eq!(0, b.capacity());
96+
/// // Creating space for 1 bit results in 64 bytes (space for 512 bits)
97+
/// // (64 is the minimum allocation size for 64 bit architectures)
98+
/// let mut b = BooleanBufferBuilder::new(1);
99+
/// assert_eq!(512, b.capacity());
100+
/// // 1000 bits requires 128 bytes (space for 1024 bits)
101+
/// b.append_n(1000, true);
102+
/// assert_eq!(1024, b.capacity());
103+
/// ```
87104
#[inline]
88105
pub fn capacity(&self) -> usize {
89106
self.buffer.capacity() * 8

arrow-buffer/src/builder/null.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl NullBufferBuilder {
217217
self.bitmap_builder.as_mut().map(|b| b.as_slice_mut())
218218
}
219219

220-
/// Return the allocated size of this builder, in bytes, useful for memory accounting.
220+
/// Return the allocated size of this builder, in bits, useful for memory accounting.
221221
pub fn allocated_size(&self) -> usize {
222222
self.bitmap_builder
223223
.as_ref()

0 commit comments

Comments
 (0)