Skip to content

Commit 5ef3df8

Browse files
committed
add is_only function to EncodingMask
1 parent d8d2afc commit 5ef3df8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

parquet/src/basic.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,11 @@ impl EncodingMask {
737737
self.0 & (1 << (val as i32)) != 0
738738
}
739739

740+
/// Test if this mask has only the bit for the given [`Encoding`] set.
741+
pub fn is_only(&self, val: Encoding) -> bool {
742+
self.0 == (1 << (val as i32))
743+
}
744+
740745
/// Test if all [`Encoding`]s in a given set are present in this mask.
741746
pub fn all_set<'a>(&self, mut encodings: impl Iterator<Item = &'a Encoding>) -> bool {
742747
encodings.all(|&e| self.is_set(e))
@@ -2498,4 +2503,14 @@ mod tests {
24982503
"Parquet error: Attempt to create invalid mask: 0x2"
24992504
);
25002505
}
2506+
2507+
#[test]
2508+
fn test_encoding_mask_is_only() {
2509+
let mask = EncodingMask::new_from_encodings([Encoding::PLAIN].iter());
2510+
assert!(mask.is_only(Encoding::PLAIN));
2511+
2512+
let mask =
2513+
EncodingMask::new_from_encodings([Encoding::PLAIN, Encoding::PLAIN_DICTIONARY].iter());
2514+
assert!(!mask.is_only(Encoding::PLAIN));
2515+
}
25012516
}

0 commit comments

Comments
 (0)