[][src]Trait arrow::array::BufferBuilderTrait

pub trait BufferBuilderTrait<T: ArrowPrimitiveType> {
    fn new(capacity: usize) -> Self;
fn len(&self) -> usize;
fn is_empty(&self) -> bool;
fn capacity(&self) -> usize;
fn advance(&mut self, n: usize) -> Result<()>;
fn reserve(&mut self, n: usize) -> Result<()>;
fn append(&mut self, value: T::Native) -> Result<()>;
fn append_n(&mut self, n: usize, value: T::Native) -> Result<()>;
fn append_slice(&mut self, slice: &[T::Native]) -> Result<()>;
fn finish(&mut self) -> Buffer; }

Trait for simplifying the construction of Buffers.

This trait is used mainly to offer separate implementations for numeric types and boolean types, while still be able to call methods on buffer builder with generic primitive type. Separate implementations of this trait allow to add implementation-details, e.g. the implementation for boolean types uses bit-packing.

Required methods

fn new(capacity: usize) -> Self

Creates a new builder with initial capacity for at least capacity elements of type T.

The capacity can later be manually adjusted with the reserve() method. Also the append(), append_slice() and advance() methods automatically increase the capacity if needed.

Example:

use arrow::array::{UInt8BufferBuilder, BufferBuilderTrait};

let mut builder = UInt8BufferBuilder::new(10);

assert!(builder.capacity() >= 10);

fn len(&self) -> usize

Returns the current number of array elements in the internal buffer.

Example:

use arrow::array::{UInt8BufferBuilder, BufferBuilderTrait};

let mut builder = UInt8BufferBuilder::new(10);
builder.append(42);

assert_eq!(builder.len(), 1);

fn is_empty(&self) -> bool

Returns whether the internal buffer is empty.

Example:

use arrow::array::{UInt8BufferBuilder, BufferBuilderTrait};

let mut builder = UInt8BufferBuilder::new(10);
builder.append(42);

assert_eq!(builder.is_empty(), false);

fn capacity(&self) -> usize

Returns the actual capacity (number of elements) of the internal buffer.

Note: the internal capacity returned by this method might be larger than what you'd expect after setting the capacity in the new() or reserve() functions.

fn advance(&mut self, n: usize) -> Result<()>

Increases the number of elements in the internal buffer by n and resizes the buffer as needed.

The values of the newly added elements are undefined. This method is usually used when appending NULL values to the buffer as they still require physical memory space.

Example:

use arrow::array::{UInt8BufferBuilder, BufferBuilderTrait};

let mut builder = UInt8BufferBuilder::new(10);
builder.advance(2);

assert_eq!(builder.len(), 2);

fn reserve(&mut self, n: usize) -> Result<()>

Reserves memory for at least n more elements of type T.

Example:

use arrow::array::{UInt8BufferBuilder, BufferBuilderTrait};

let mut builder = UInt8BufferBuilder::new(10);
builder.reserve(10);

assert!(builder.capacity() >= 20);

fn append(&mut self, value: T::Native) -> Result<()>

Appends a value of type T into the builder, growing the internal buffer as needed.

Example:

use arrow::array::{UInt8BufferBuilder, BufferBuilderTrait};

let mut builder = UInt8BufferBuilder::new(10);
builder.append(42);

assert_eq!(builder.len(), 1);

fn append_n(&mut self, n: usize, value: T::Native) -> Result<()>

Appends a value of type T into the builder N times, growing the internal buffer as needed.

Example:

use arrow::array::{UInt8BufferBuilder, BufferBuilderTrait};

let mut builder = UInt8BufferBuilder::new(10);
builder.append_n(10, 42);

assert_eq!(builder.len(), 10);

fn append_slice(&mut self, slice: &[T::Native]) -> Result<()>

Appends a slice of type T, growing the internal buffer as needed.

Example:

use arrow::array::{UInt8BufferBuilder, BufferBuilderTrait};

let mut builder = UInt8BufferBuilder::new(10);
builder.append_slice(&[42, 44, 46]);

assert_eq!(builder.len(), 3);

fn finish(&mut self) -> Buffer

Resets this builder and returns an immutable Buffer.

Example:

use arrow::array::{UInt8BufferBuilder, BufferBuilderTrait};

let mut builder = UInt8BufferBuilder::new(10);
builder.append_slice(&[42, 44, 46]);

let buffer = builder.finish();

assert_eq!(unsafe { buffer.typed_data::<u8>() }, &[42, 44, 46]);
Loading content...

Implementors

impl BufferBuilderTrait<BooleanType> for BufferBuilder<BooleanType>[src]

impl<T: ArrowPrimitiveType> BufferBuilderTrait<T> for BufferBuilder<T>[src]

Loading content...