uqa_storage/clustered_postings/
read_cursor.rs1use super::{DocId, PostingCursor, PostingScore, StorageBackendResult};
10use crate::read_control::StorageReadControl;
11use uqa_core::memory::MemoryReservation;
12
13pub struct BudgetedPostingReadCursor<'a> {
15 cursor: Box<dyn PostingReadCursor + 'a>,
16 _memory: MemoryReservation,
18}
19impl<'a> BudgetedPostingReadCursor<'a> {
20 pub fn new<T: PostingReadCursor + 'a>(
21 cursor: T,
22 control: &StorageReadControl,
23 ) -> StorageBackendResult<Self> {
24 control.check()?;
25 let memory = control.memory().reserve(size_of::<T>())?;
26 Ok(Self {
27 cursor: Box::new(cursor),
28 _memory: memory,
29 })
30 }
31}
32impl PostingReadCursor for BudgetedPostingReadCursor<'_> {
33 fn doc_freq(&self) -> u64 {
34 self.cursor.doc_freq()
35 }
36 fn current(&self) -> Option<PostingScore> {
37 self.cursor.current()
38 }
39 fn advance(&mut self) -> StorageBackendResult<Option<PostingScore>> {
40 self.cursor.advance()
41 }
42 fn advance_to(&mut self, target: DocId) -> StorageBackendResult<Option<PostingScore>> {
43 self.cursor.advance_to(target)
44 }
45}
46
47pub trait PostingReadCursor: Send {
49 fn doc_freq(&self) -> u64;
50 fn current(&self) -> Option<PostingScore>;
51 fn advance(&mut self) -> StorageBackendResult<Option<PostingScore>>;
52 fn advance_to(&mut self, target: DocId) -> StorageBackendResult<Option<PostingScore>>;
53}
54
55pub struct OwnedPostingReadCursor(pub Box<dyn PostingCursor>);
57
58impl PostingReadCursor for OwnedPostingReadCursor {
59 fn doc_freq(&self) -> u64 {
60 self.0.doc_freq()
61 }
62 fn current(&self) -> Option<PostingScore> {
63 self.0.current()
64 }
65 fn advance(&mut self) -> StorageBackendResult<Option<PostingScore>> {
66 self.0.advance()
67 }
68 fn advance_to(&mut self, target: DocId) -> StorageBackendResult<Option<PostingScore>> {
69 self.0.advance_to(target)
70 }
71}