Skip to content

Commit

Permalink
rename capacity to item_capacity in bytes and utf8 array builder
Browse files Browse the repository at this point in the history
Signed-off-by: Runji Wang <[email protected]>
  • Loading branch information
wangrunji0408 committed Jun 7, 2024
1 parent b6972f3 commit 2c52ee3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
15 changes: 10 additions & 5 deletions src/common/src/array/bytes_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,24 @@ pub struct BytesArrayBuilder {
impl ArrayBuilder for BytesArrayBuilder {
type ArrayType = BytesArray;

fn new(capacity: usize) -> Self {
let mut offset = Vec::with_capacity(capacity + 1);
/// Creates a new `BytesArrayBuilder`.
///
/// `item_capacity` is the number of items to pre-allocate. The size of the preallocated
/// buffer of offsets is the number of items plus one.
/// No additional memory is pre-allocated for the data buffer.
fn new(item_capacity: usize) -> Self {
let mut offset = Vec::with_capacity(item_capacity + 1);
offset.push(0);
Self {
offset,
data: Vec::with_capacity(capacity),
data: Vec::with_capacity(0),
bitmap: BitmapBuilder::with_capacity(capacity),
}
}

fn with_type(capacity: usize, ty: DataType) -> Self {
fn with_type(item_capacity: usize, ty: DataType) -> Self {
assert_eq!(ty, DataType::Bytea);
Self::new(capacity)
Self::new(item_capacity)
}

fn append_n<'a>(&'a mut self, n: usize, value: Option<&'a [u8]>) {
Expand Down
13 changes: 9 additions & 4 deletions src/common/src/array/utf8_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,20 @@ pub struct Utf8ArrayBuilder {
impl ArrayBuilder for Utf8ArrayBuilder {
type ArrayType = Utf8Array;

fn new(capacity: usize) -> Self {
/// Creates a new `Utf8ArrayBuilder`.
///
/// `item_capacity` is the number of items to pre-allocate. The size of the preallocated
/// buffer of offsets is the number of items plus one.
/// No additional memory is pre-allocated for the data buffer.
fn new(item_capacity: usize) -> Self {
Self {
bytes: BytesArrayBuilder::new(capacity),
bytes: BytesArrayBuilder::new(item_capacity),
}
}

fn with_type(capacity: usize, ty: DataType) -> Self {
fn with_type(item_capacity: usize, ty: DataType) -> Self {
assert_eq!(ty, DataType::Varchar);
Self::new(capacity)
Self::new(item_capacity)
}

#[inline]
Expand Down

0 comments on commit 2c52ee3

Please sign in to comment.