Skip to content

Commit 5b878cf

Browse files
committed
reorganize the NodeId to make the append works again and add a test
1 parent a72d20d commit 5b878cf

7 files changed

+391
-346
lines changed

src/node_id.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use crate::ItemId;
99
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1010
#[repr(u8)]
1111
pub enum NodeMode {
12-
Item = 0,
12+
Metadata = 0,
1313
Tree = 1,
14-
Metadata = 2,
14+
Item = 2,
1515
}
1616

1717
impl TryFrom<u8> for NodeMode {

src/tests/binary_quantized.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ fn write_and_retrieve_binary_quantized_vector() {
4747
insta::assert_snapshot!(handle, @r###"
4848
==================
4949
Dumping index 0
50-
Item 0: Leaf(Leaf { header: NodeHeaderBinaryQuantizedEuclidean { bias: 0.0 }, vector: [-1.0000, -1.0000, 1.0000, -1.0000, 1.0000, 1.0000, -1.0000, 1.0000, -1.0000, -1.0000, "other ..."] })
51-
Tree 0: Descendants(Descendants { descendants: [0] })
5250
Root: Metadata { dimensions: 16, items: RoaringBitmap<[0]>, roots: [0], distance: "binary quantized euclidean" }
51+
Tree 0: Descendants(Descendants { descendants: [0] })
52+
Item 0: Leaf(Leaf { header: NodeHeaderBinaryQuantizedEuclidean { bias: 0.0 }, vector: [-1.0000, -1.0000, 1.0000, -1.0000, 1.0000, 1.0000, -1.0000, 1.0000, -1.0000, -1.0000, "other ..."] })
5353
"###);
5454
}

src/tests/reader.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ fn two_dimension_on_a_line() {
112112
let reader = Reader::<Euclidean>::open(&rtxn, 0, handle.database).unwrap();
113113

114114
// if we can't look into enough nodes we find some random points
115-
let ret = reader.nns(5).search_k(NonZeroUsize::new(1).unwrap()).by_item(&rtxn, 0).unwrap();
115+
let ret = reader.nns(5).search_k(NonZeroUsize::new(1).unwrap()).by_item(&rtxn, 1).unwrap();
116116
insta::assert_snapshot!(NnsRes(ret), @r###"
117-
id(48): distance(48)
118-
id(92): distance(92)
117+
id(48): distance(47)
118+
id(92): distance(91)
119119
"###);
120120

121121
// if we can look into all the node there is no inifinite loop and it works
@@ -131,11 +131,11 @@ fn two_dimension_on_a_line() {
131131

132132
let ret = reader.nns(5).by_item(&rtxn, 0).unwrap();
133133
insta::assert_snapshot!(NnsRes(ret), @r###"
134+
id(0): distance(0)
134135
id(1): distance(1)
135136
id(2): distance(2)
136137
id(3): distance(3)
137138
id(4): distance(4)
138-
id(5): distance(5)
139139
"###);
140140
}
141141

@@ -162,11 +162,11 @@ fn two_dimension_on_a_column() {
162162
let ret = reader.nns(5).by_item(&rtxn, 0).unwrap();
163163

164164
insta::assert_snapshot!(NnsRes(ret), @r###"
165+
id(0): distance(0)
165166
id(1): distance(1)
166167
id(2): distance(2)
167168
id(3): distance(3)
168169
id(4): distance(4)
169-
id(5): distance(5)
170170
"###);
171171
}
172172

src/tests/snapshots/arroy__tests__writer__write_and_update_lot_of_random_points-2.snap

+101-101
Large diffs are not rendered by default.

src/tests/snapshots/arroy__tests__writer__write_and_update_lot_of_random_points.snap

+99-99
Large diffs are not rendered by default.

src/tests/writer.rs

+181-137
Large diffs are not rendered by default.

src/writer.rs

+1
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ impl<D: Distance> Writer<D> {
265265
.remap_data_type::<RoaringBitmapCodec>()
266266
.get(wtxn, &Key::updated(self.index))?
267267
.unwrap_or_default();
268+
// We cannot append here because we may have removed an item with a larger id before
268269
updated.insert(item);
269270
self.database.remap_data_type::<RoaringBitmapCodec>().put(
270271
wtxn,

0 commit comments

Comments
 (0)