pub struct Postings { /* private fields */ }Expand description
A posting list held in RAM: elements sorted by record id, unique ids,
every element carrying its tail_max ceiling (see the module docs).
Implementations§
Source§impl Postings
impl Postings
Sourcepub fn from_pairs<I>(pairs: I) -> Self
pub fn from_pairs<I>(pairs: I) -> Self
Build from (id, weight) pairs in any order. Later pairs win over
earlier ones with the same id.
Sourcepub fn from_sorted_pairs(pairs: &[(RecordId, Weight)]) -> Self
pub fn from_sorted_pairs(pairs: &[(RecordId, Weight)]) -> Self
Build from pairs already sorted by strictly increasing id. Panics in debug builds if the order is violated.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn cursor(&self) -> SliceCursor<'_>
pub fn cursor(&self) -> SliceCursor<'_>
A cursor at the start of the list.
Sourcepub fn upsert(&mut self, id: RecordId, weight: Weight) -> Option<Weight>
pub fn upsert(&mut self, id: RecordId, weight: Weight) -> Option<Weight>
Insert id with weight, or replace its weight if it is already
present. Returns the previous weight when replacing.
Appending an id above every existing one costs O(1) unless the new weight raises existing ceilings, and then only the raised prefix is rewritten: inserting a corpus in id order is amortised O(1) per element for weights without a rising trend.
Sourcepub fn delete(&mut self, id: RecordId) -> Option<Weight>
pub fn delete(&mut self, id: RecordId) -> Option<Weight>
Remove id. Returns its weight if it was present.
Sourcepub fn recompute_tail_max(&mut self)
pub fn recompute_tail_max(&mut self)
Recompute every ceiling from scratch (after bulk edits through
items_mut).
Sourcepub fn items_mut(&mut self) -> &mut Vec<Posting>
pub fn items_mut(&mut self) -> &mut Vec<Posting>
Mutable access to the raw elements for bulk edits. The caller must
keep ids sorted and unique, and call
recompute_tail_max afterwards.
Sourcepub fn check_invariants(&self) -> Result<(), String>
pub fn check_invariants(&self) -> Result<(), String>
Check the structural invariants: ids strictly increasing, and every
tail_max equal to the maximum weight of its inclusive suffix.
Returns a description of the first violation.