mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-31 15:31:53 +08:00
Make the CboRoaringBitmapCodec support intersection on deserialization
This commit is contained in:
parent
e4a69c5ac3
commit
4ca4a3f954
@ -1,5 +1,5 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::io;
|
use std::io::{self, Cursor};
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
|
|
||||||
use byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
|
use byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
|
||||||
@ -57,6 +57,24 @@ impl CboRoaringBitmapCodec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn intersection_with_serialized(
|
||||||
|
mut bytes: &[u8],
|
||||||
|
other: &RoaringBitmap,
|
||||||
|
) -> io::Result<RoaringBitmap> {
|
||||||
|
// See above `deserialize_from` method for implementation details.
|
||||||
|
if bytes.len() <= THRESHOLD * size_of::<u32>() {
|
||||||
|
let mut bitmap = RoaringBitmap::new();
|
||||||
|
while let Ok(integer) = bytes.read_u32::<NativeEndian>() {
|
||||||
|
if other.contains(integer) {
|
||||||
|
bitmap.insert(integer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(bitmap)
|
||||||
|
} else {
|
||||||
|
other.intersection_with_serialized_unchecked(Cursor::new(bytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Merge serialized CboRoaringBitmaps in a buffer.
|
/// Merge serialized CboRoaringBitmaps in a buffer.
|
||||||
///
|
///
|
||||||
/// if the merged values length is under the threshold, values are directly
|
/// if the merged values length is under the threshold, values are directly
|
||||||
|
Loading…
x
Reference in New Issue
Block a user