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

Method new

arrow-buffer/src/util/bit_chunk_iterator.rs:42–132  ·  view source on GitHub ↗

Create a from a byte array, and and an offset and length in bits

(buffer: &'a [u8], offset: usize, len: usize)

Source from the content-addressed store, hash-verified

40impl<'a> UnalignedBitChunk<'a> {
41 /// Create a from a byte array, and and an offset and length in bits
42 pub fn new(buffer: &'a [u8], offset: usize, len: usize) -> Self {
43 if len == 0 {
44 return Self {
45 lead_padding: 0,
46 trailing_padding: 0,
47 prefix: None,
48 chunks: &[],
49 suffix: None,
50 };
51 }
52
53 let byte_offset = offset / 8;
54 let offset_padding = offset % 8;
55
56 let bytes_len = (len + offset_padding).div_ceil(8);
57 let buffer = &buffer[byte_offset..byte_offset + bytes_len];
58
59 let prefix_mask = compute_prefix_mask(offset_padding);
60
61 // If less than 8 bytes, read into prefix
62 if buffer.len() <= 8 {
63 let (suffix_mask, trailing_padding) = compute_suffix_mask(len, offset_padding);
64 let prefix = read_u64(buffer) & suffix_mask & prefix_mask;
65
66 return Self {
67 lead_padding: offset_padding,
68 trailing_padding,
69 prefix: Some(prefix),
70 chunks: &[],
71 suffix: None,
72 };
73 }
74
75 // If less than 16 bytes, read into prefix and suffix
76 if buffer.len() <= 16 {
77 let (suffix_mask, trailing_padding) = compute_suffix_mask(len, offset_padding);
78 let prefix = read_u64(&buffer[..8]) & prefix_mask;
79 let suffix = read_u64(&buffer[8..]) & suffix_mask;
80
81 return Self {
82 lead_padding: offset_padding,
83 trailing_padding,
84 prefix: Some(prefix),
85 chunks: &[],
86 suffix: Some(suffix),
87 };
88 }
89
90 // Read into prefix and suffix as needed
91 let (prefix, mut chunks, suffix) = unsafe { buffer.align_to::<u64>() };
92 assert!(
93 prefix.len() < 8 && suffix.len() < 8,
94 "align_to did not return largest possible aligned slice"
95 );
96
97 let (alignment_padding, prefix) = match (offset_padding, prefix.is_empty()) {
98 (0, true) => (0, None),
99 (_, true) => {

Callers

nothing calls this directly

Calls 6

compute_prefix_maskFunction · 0.85
compute_suffix_maskFunction · 0.85
read_u64Function · 0.70
lenMethod · 0.45
is_emptyMethod · 0.45
checked_addMethod · 0.45

Tested by

no test coverage detected