Skip to content

Commit 4b43f6d

Browse files
committed
Add a method on reader to get all the item ids
1 parent 6470bb7 commit 4b43f6d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/reader.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ impl<'t, D: Distance> Reader<'t, D> {
7171
self.items.len()
7272
}
7373

74+
/// Returns all the item ids contained in this index.
75+
pub fn item_ids(&self) -> &RoaringBitmap {
76+
&self.items
77+
}
78+
7479
/// Returns the index of this reader in the database.
7580
pub fn index(&self) -> u16 {
7681
self.index

src/tests/reader.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,23 @@ fn two_dimension_on_a_column() {
169169
"###);
170170
}
171171

172+
#[test]
173+
fn get_item_ids() {
174+
let handle = create_database();
175+
let mut wtxn = handle.env.write_txn().unwrap();
176+
let writer = Writer::new(handle.database, 0, 2);
177+
for i in 0..10 {
178+
writer.add_item(&mut wtxn, i, &[0.0, i as f32]).unwrap();
179+
}
180+
181+
writer.build(&mut wtxn, &mut rng(), Some(50)).unwrap();
182+
183+
let reader = Reader::<Euclidean>::open(&wtxn, 0, handle.database).unwrap();
184+
let ret = reader.item_ids();
185+
186+
insta::assert_debug_snapshot!(ret, @"RoaringBitmap<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>");
187+
}
188+
172189
#[test]
173190
fn filtering() {
174191
let handle = create_database();

0 commit comments

Comments
 (0)