|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +use roaring::RoaringTreemap; |
| 19 | + |
| 20 | +#[allow(unused)] |
| 21 | +pub struct DeleteVector { |
| 22 | + inner: RoaringTreemap, |
| 23 | +} |
| 24 | + |
| 25 | +impl DeleteVector { |
| 26 | + pub fn iter(&self) -> DeleteVectorIterator { |
| 27 | + let mut iter = self.inner.bitmaps(); |
| 28 | + match iter.next() { |
| 29 | + Some((high_bits, bitmap)) => { |
| 30 | + DeleteVectorIterator { |
| 31 | + inner: Some(DeleteVectorIteratorInner { |
| 32 | + // iter, |
| 33 | + high_bits: (high_bits as u64) << 32, |
| 34 | + bitmap_iter: bitmap.iter(), |
| 35 | + }), |
| 36 | + } |
| 37 | + } |
| 38 | + _ => DeleteVectorIterator { inner: None }, |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +pub struct DeleteVectorIterator<'a> { |
| 44 | + inner: Option<DeleteVectorIteratorInner<'a>>, |
| 45 | +} |
| 46 | + |
| 47 | +struct DeleteVectorIteratorInner<'a> { |
| 48 | + // TODO: roaring::treemap::iter::BitmapIter is currently private. |
| 49 | + // See https://github.com/RoaringBitmap/roaring-rs/issues/312 |
| 50 | + // iter: roaring::treemap::iter::BitmapIter<'a>, |
| 51 | + high_bits: u64, |
| 52 | + bitmap_iter: roaring::bitmap::Iter<'a>, |
| 53 | +} |
| 54 | + |
| 55 | +impl Iterator for DeleteVectorIterator<'_> { |
| 56 | + type Item = u64; |
| 57 | + |
| 58 | + fn next(&mut self) -> Option<Self::Item> { |
| 59 | + let Some(ref mut inner) = &mut self.inner else { |
| 60 | + return None; |
| 61 | + }; |
| 62 | + |
| 63 | + if let Some(lower) = inner.bitmap_iter.next() { |
| 64 | + return Some(inner.high_bits & lower as u64); |
| 65 | + }; |
| 66 | + |
| 67 | + // TODO: roaring::treemap::iter::BitmapIter is currently private. |
| 68 | + // See https://github.com/RoaringBitmap/roaring-rs/issues/312 |
| 69 | + |
| 70 | + // replace with commented-out code below once BitmapIter is pub, |
| 71 | + // or use RoaringTreemap::iter if `advance_to` gets implemented natively |
| 72 | + None |
| 73 | + |
| 74 | + // let Some((high_bits, bitmap)) = inner.iter.next() else { |
| 75 | + // self.inner = None; |
| 76 | + // return None; |
| 77 | + // }; |
| 78 | + // |
| 79 | + // inner.high_bits = (high_bits as u64) << 32; |
| 80 | + // inner.bitmap_iter = bitmap.iter(); |
| 81 | + // |
| 82 | + // self.next() |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +impl<'a> DeleteVectorIterator<'a> { |
| 87 | + pub fn advance_to(&'a mut self, _pos: u64) { |
| 88 | + // TODO |
| 89 | + } |
| 90 | +} |
0 commit comments