Skip to main content

Needle

Struct Needle 

Source
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>

Source

pub fn new(bytes: &'a [u8]) -> Needle<'a>

A needle from bytes, which is what a command line argument is.

Source

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.

Source

pub const fn bytes(&self) -> &'a [u8]

The member as bytes, which is what a caller collecting an answer wants.

Trait Implementations§

Source§

impl<'a> Clone for Needle<'a>

Source§

fn clone(&self) -> Needle<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Needle<'a>

Source§

impl<'a> Debug for Needle<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Needle<'a>

§

impl<'a> RefUnwindSafe for Needle<'a>

§

impl<'a> Send for Needle<'a>

§

impl<'a> Sync for Needle<'a>

§

impl<'a> Unpin for Needle<'a>

§

impl<'a> UnsafeUnpin for Needle<'a>

§

impl<'a> UnwindSafe for Needle<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.