From bb885a581001e3f299d62da05252d1a069d281c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sun, 1 Sep 2024 23:20:19 +0200 Subject: [PATCH] Fix the merge for roaring bitmap --- milli/src/update/new/mod.rs | 47 +++++++++++++++---------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/milli/src/update/new/mod.rs b/milli/src/update/new/mod.rs index 3d9800657..a6ac38abe 100644 --- a/milli/src/update/new/mod.rs +++ b/milli/src/update/new/mod.rs @@ -402,37 +402,28 @@ mod indexer { del: Option<&[u8]>, add: Option<&[u8]>, ) -> Result { - let bitmap = match current { - Some(current_bitmap_bytes) => { - let bitmap_without_del = match del { - Some(del_bytes) => { - let del_bitmap = CboRoaringBitmapCodec::deserialize_from(del_bytes)?; - CboRoaringBitmapCodec::intersection_with_serialized( - current_bitmap_bytes, - &del_bitmap, - )? - } - None => CboRoaringBitmapCodec::deserialize_from(current_bitmap_bytes)?, - }; + let current = current.map(CboRoaringBitmapCodec::deserialize_from).transpose()?; + let del = del.map(CboRoaringBitmapCodec::deserialize_from).transpose()?; + let add = add.map(CboRoaringBitmapCodec::deserialize_from).transpose()?; - match add { - Some(add_bytes) => { - let add = CboRoaringBitmapCodec::deserialize_from(add_bytes)?; - bitmap_without_del | add - } - None => bitmap_without_del, + match (current, del, add) { + (None, None, None) => Ok(Operation::Ignore), // but it's strange + (None, None, Some(add)) => Ok(Operation::Write(add)), + (None, Some(_del), None) => Ok(Operation::Ignore), // but it's strange + (None, Some(_del), Some(add)) => Ok(Operation::Write(add)), + (Some(_current), None, None) => Ok(Operation::Ignore), // but it's strange + (Some(current), None, Some(add)) => Ok(Operation::Write(current | add)), + (Some(current), Some(del), add) => { + let output = match add { + Some(add) => (current - del) | add, + None => current - del, + }; + if output.is_empty() { + Ok(Operation::Delete) + } else { + Ok(Operation::Write(output)) } } - None => match add { - Some(add_bytes) => CboRoaringBitmapCodec::deserialize_from(add_bytes)?, - None => return Ok(Operation::Ignore), - }, - }; - - if bitmap.is_empty() { - Ok(Operation::Delete) - } else { - Ok(Operation::Write(bitmap)) } }