pub struct Needle<'a> { /* private fields */ }Expand description
A member on its way to being asked about, in every form the three representations want it in.
Set algebra walks one set and asks every other set the same question about
each member, and the three representations do not want the question in the
same shape. An intset wants a number, a listpack wants bytes and a number
because it holds both kinds, and an element table wants bytes and their
hash. Asking through Set::contains would redo all of that per question:
a parse for the intset, another parse inside the listpack, and a hash per
table. This does each once per member and then asks k - 1 times.
The hash is computed whether or not any operand is a table, which is waste when none is. It is waste worth taking, because the sets where it is wasted are an intset or a listpack, which are capped at a few hundred members, and an operation over sets that small is finished before the saving could have been measured. The sets where the hash pays are the large ones, and those are tables by definition.
Implementations§
Source§impl<'a> Needle<'a>
impl<'a> Needle<'a>
Sourcepub fn new(bytes: &'a [u8]) -> Needle<'a>
pub fn new(bytes: &'a [u8]) -> Needle<'a>
A needle from bytes, which is what a command line argument is.
Sourcepub fn of(member: Member<'a>, digits: &'a mut [u8; 21]) -> Needle<'a>
pub fn of(member: Member<'a>, digits: &'a mut [u8; 21]) -> Needle<'a>
A needle from a member walked out of a set.
digits is where an integer member’s text goes, because an intset holds
the number and the digits do not exist anywhere until somebody writes
them. It is the caller’s buffer rather than a field so that the needle
stays a borrow and the buffer is written once per member rather than
allocated once per member.
A member that came out as bytes is still parsed, because the set being
asked may be an intset and SINTER ints strings has to find the members
they share. A member that came out as a number is not, which is the
whole saving.