Skip to content

Commit

Permalink
Add capacity in Buffer struct
Browse files Browse the repository at this point in the history
  • Loading branch information
sunchao committed Feb 15, 2020
1 parent d9be1df commit 1ab4ccc
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 52 deletions.
6 changes: 3 additions & 3 deletions rust/arrow/src/array/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2821,7 +2821,7 @@ mod tests {
#[should_panic(expected = "memory is not aligned")]
fn test_primitive_array_alignment() {
let ptr = memory::allocate_aligned(8);
let buf = unsafe { Buffer::from_raw_parts(ptr, 8) };
let buf = unsafe { Buffer::from_raw_parts(ptr, 8, 8) };
let buf2 = buf.slice(1);
let array_data = ArrayData::builder(DataType::Int32).add_buffer(buf2).build();
Int32Array::from(array_data);
Expand All @@ -2831,7 +2831,7 @@ mod tests {
#[should_panic(expected = "memory is not aligned")]
fn test_list_array_alignment() {
let ptr = memory::allocate_aligned(8);
let buf = unsafe { Buffer::from_raw_parts(ptr, 8) };
let buf = unsafe { Buffer::from_raw_parts(ptr, 8, 8) };
let buf2 = buf.slice(1);

let values: [i32; 8] = [0; 8];
Expand All @@ -2851,7 +2851,7 @@ mod tests {
#[should_panic(expected = "memory is not aligned")]
fn test_binary_array_alignment() {
let ptr = memory::allocate_aligned(8);
let buf = unsafe { Buffer::from_raw_parts(ptr, 8) };
let buf = unsafe { Buffer::from_raw_parts(ptr, 8, 8) };
let buf2 = buf.slice(1);

let values: [u8; 12] = [0; 12];
Expand Down
22 changes: 11 additions & 11 deletions rust/arrow/src/array/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,15 +986,15 @@ mod tests {
assert_eq!(0, b.len());
assert_eq!(16, b.capacity());
let a = b.finish();
assert_eq!(64, a.len());
assert_eq!(0, a.len());
}

#[test]
fn test_builder_i32_alloc_zero_bytes() {
let mut b = Int32BufferBuilder::new(0);
b.append(123).unwrap();
let a = b.finish();
assert_eq!(64, a.len());
assert_eq!(4, a.len());
}

#[test]
Expand All @@ -1005,7 +1005,7 @@ mod tests {
}
assert_eq!(16, b.capacity());
let a = b.finish();
assert_eq!(64, a.len()); // 16 * size_of(i32)
assert_eq!(20, a.len());
}

#[test]
Expand All @@ -1017,7 +1017,7 @@ mod tests {
}
assert_eq!(32, b.capacity());
let a = b.finish();
assert_eq!(128, a.len()); // 32 * size_of(i32)
assert_eq!(80, a.len());
}

#[test]
Expand All @@ -1028,7 +1028,7 @@ mod tests {
b.append(i).unwrap();
}
let mut a = b.finish();
assert_eq!(64, a.len());
assert_eq!(40, a.len());
assert_eq!(0, b.len());
assert_eq!(0, b.capacity());

Expand All @@ -1038,7 +1038,7 @@ mod tests {
}
assert_eq!(32, b.capacity());
a = b.finish();
assert_eq!(128, a.len());
assert_eq!(80, a.len());
}

#[test]
Expand All @@ -1064,12 +1064,12 @@ mod tests {
b.append_slice("Hello, ".as_bytes()).unwrap();
b.append_slice("World!".as_bytes()).unwrap();
let buffer = b.finish();
assert_eq!(64, buffer.len());
assert_eq!(13, buffer.len());

let mut b = Int32BufferBuilder::new(0);
b.append_slice(&[32, 54]).unwrap();
let buffer = b.finish();
assert_eq!(64, buffer.len());
assert_eq!(8, buffer.len());
}

#[test]
Expand All @@ -1082,14 +1082,14 @@ mod tests {
assert_eq!(4, b.len());
assert_eq!(512, b.capacity());
let buffer = b.finish();
assert_eq!(64, buffer.len());
assert_eq!(1, buffer.len());

let mut b = BooleanBufferBuilder::new(4);
b.append_slice(&[false, true, false, true]).unwrap();
assert_eq!(4, b.len());
assert_eq!(512, b.capacity());
let buffer = b.finish();
assert_eq!(64, buffer.len());
assert_eq!(1, buffer.len());
}

#[test]
Expand All @@ -1100,7 +1100,7 @@ mod tests {
assert_eq!(4, b.len());
assert_eq!(16, b.capacity());
let buffer = b.finish();
assert_eq!(64, buffer.len());
assert_eq!(16, buffer.len());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion rust/arrow/src/array/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ mod tests {
assert_eq!(10, arr_data.null_count());
assert_eq!(5, arr_data.offset());
assert_eq!(1, arr_data.buffers().len());
assert_eq!([0, 1, 2, 3], arr_data.buffers()[0].data()[..4]);
assert_eq!(&[0, 1, 2, 3], arr_data.buffers()[0].data());
assert_eq!(1, arr_data.child_data().len());
assert_eq!(child_arr_data, arr_data.child_data()[0]);
}
Expand Down
Loading

0 comments on commit 1ab4ccc

Please sign in to comment.