pub fn builder_with_capacity(
dtype: &DType,
capacity: usize,
) -> Box<dyn ArrayBuilder>
Expand description
Construct a new canonical builder for the given DType
.
ยงExample
use vortex_array::builders::{builder_with_capacity, ArrayBuilderExt};
use vortex_dtype::{DType, Nullability};
// Create a new builder for string data.
let mut builder = builder_with_capacity(&DType::Utf8(Nullability::NonNullable), 4);
builder.append_scalar(&"a".into()).unwrap();
builder.append_scalar(&"b".into()).unwrap();
builder.append_scalar(&"c".into()).unwrap();
builder.append_scalar(&"d".into()).unwrap();
let strings = builder.finish();
assert_eq!(strings.scalar_at(0).unwrap(), "a".into());
assert_eq!(strings.scalar_at(1).unwrap(), "b".into());
assert_eq!(strings.scalar_at(2).unwrap(), "c".into());
assert_eq!(strings.scalar_at(3).unwrap(), "d".into());