MCPcopy Create free account
hub / github.com/apache/arrow-rs / bit_slice_length_preserved

Function bit_slice_length_preserved

arrow-buffer/src/buffer/immutable.rs:1025–1055  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1023
1024 #[test]
1025 fn bit_slice_length_preserved() {
1026 // Create a boring buffer
1027 let buf = Buffer::from_iter(std::iter::repeat_n(true, 64));
1028
1029 let assert_preserved = |offset: usize, len: usize| {
1030 let new_buf = buf.bit_slice(offset, len);
1031 assert_eq!(new_buf.len(), bit_util::ceil(len, 8));
1032
1033 // if the offset is not byte-aligned, we have to create a deep copy to a new buffer
1034 // (since the `offset` value inside a Buffer is byte-granular, not bit-granular), so
1035 // checking the offset should always return 0 if so. If the offset IS byte-aligned, we
1036 // want to make sure it doesn't unnecessarily create a deep copy.
1037 if offset % 8 == 0 {
1038 assert_eq!(new_buf.ptr_offset(), offset / 8);
1039 } else {
1040 assert_eq!(new_buf.ptr_offset(), 0);
1041 }
1042 };
1043
1044 // go through every available value for offset
1045 for o in 0..=64 {
1046 // and go through every length that could accompany that offset - we can't have a
1047 // situation where offset + len > 64, because that would go past the end of the buffer,
1048 // so we use the map to ensure it's in range.
1049 for l in (o..=64).map(|l| l - o) {
1050 // and we just want to make sure every one of these keeps its offset and length
1051 // when neeeded
1052 assert_preserved(o, l);
1053 }
1054 }
1055 }
1056
1057 #[test]
1058 fn test_strong_count() {

Callers

nothing calls this directly

Calls 2

bit_sliceMethod · 0.80
from_iterFunction · 0.70

Tested by

no test coverage detected