@@ -40,6 +40,8 @@ pub trait DocSet: Send {
40
40
/// of `DocSet` should support it.
41
41
///
42
42
/// Calling `seek(TERMINATED)` is also legal and is the normal way to consume a `DocSet`.
43
+ ///
44
+ /// `target` has to be larger or equal to `.doc()` when calling `seek`.
43
45
fn seek ( & mut self , target : DocId ) -> DocId {
44
46
let mut doc = self . doc ( ) ;
45
47
debug_assert ! ( doc <= target) ;
@@ -58,11 +60,22 @@ pub trait DocSet: Send {
58
60
///
59
61
/// ## API Behaviour
60
62
/// If `seek_exact` is returning true, a call to `doc()` has to return target.
61
- /// If `seek_exact` is returning false, a call to `doc()` may return the previous doc,
62
- /// which may be lower than target.
63
+ /// If `seek_exact` is returning false, a call to `doc()` may return any doc and should not be
64
+ /// used until `seek_exact` returns true again. The DocSet is considered to be in an invalid
65
+ /// state until `seek_exact` returns true again.
66
+ ///
67
+ /// target needs to be equal or larger than `doc` when in a valid state.
68
+ ///
69
+ /// Consecutive calls are not allowed to have decreasing `target` values.
70
+ ///
71
+ /// # Warning
72
+ /// This is an advanced API used by intersection. The API contract is tricky, avoid using it.
63
73
fn seek_exact ( & mut self , target : DocId ) -> bool {
64
- let doc = self . seek ( target) ;
65
- doc == target
74
+ let current_doc = self . doc ( ) ;
75
+ if current_doc < target {
76
+ self . seek ( target) ;
77
+ }
78
+ self . doc ( ) == target
66
79
}
67
80
68
81
/// Fills a given mutable buffer with the next doc ids from the
@@ -103,8 +116,11 @@ pub trait DocSet: Send {
103
116
/// length of the docset.
104
117
fn size_hint ( & self ) -> u32 ;
105
118
106
- /// Returns a best-effort hint of the
107
- /// cost to drive the docset.
119
+ /// Returns a best-effort hint of the cost to consume the entire docset.
120
+ ///
121
+ /// Consuming means calling advance until [`TERMINATED`] is returned.
122
+ /// The cost should be relative to the cost of driving a Term query,
123
+ /// which would be the number of documents in the DocSet.
108
124
///
109
125
/// By default this returns `size_hint()`.
110
126
///
0 commit comments