pub struct Signature(/* private fields */);Expand description
A tag built by setting one bit per attribute value, so that a conjunction of required values is a subset test.
Superimposed coding, which is old and still the right answer when the test has to be one instruction on a value that is already in a register. Each attribute and value pair hashes to one of 64 bits. A member’s tag is the bits for the values it has. A query’s tag is the bits for the values it requires. The member is worth ranking when it has all of the query’s bits.
Two different values can land on the same bit, so a member can pass a filter it does not really match. It can never fail one it does match, which is the direction that matters: the answers are a superset of the truth and the caller’s own predicate cuts them down, where the other way round would lose answers silently.
use yo_vector::Signature;
// What a document is tagged with, and what a query asks for.
let doc = Signature::of(&[("lang", "en".as_bytes()), ("topic", "finance".as_bytes())]);
let english = Signature::of(&[("lang", "en".as_bytes())]);
assert!(doc.covers(english));
// The other way round only holds if the two bits happened to collide.
assert!(!english.covers(doc) || english.bits() == doc.bits());Implementations§
Source§impl Signature
impl Signature
Sourcepub fn of(values: &[(&str, &[u8])]) -> Signature
pub fn of(values: &[(&str, &[u8])]) -> Signature
The signature of a set of attribute and value pairs.
Sourcepub fn insert(&mut self, attribute: &str, value: &[u8])
pub fn insert(&mut self, attribute: &str, value: &[u8])
Add one attribute and value pair to what this signature covers.
For a caller that meets the pairs one at a time rather than holding them all in a slice, which is what building a tag out of a document’s indexed fields looks like.
Sourcepub fn insert_bytes(&mut self, attribute: &[u8], value: &[u8])
pub fn insert_bytes(&mut self, attribute: &[u8], value: &[u8])
The same for an attribute that is already bytes, which is what a document path is.
Sourcepub fn bits(self) -> u64
pub fn bits(self) -> u64
The signature as the tag to hand to Partitions::insert_tagged.