Skip to main content

Intset

Struct Intset 

Source
pub struct Intset { /* private fields */ }
Expand description

A sorted packed set of integers, in one or more runs.

Implementations§

Source§

impl Intset

Source

pub fn new() -> Intset

An empty set at the narrowest width.

Source

pub fn with_capacity(n: usize) -> Intset

An empty set with room for n members at the narrowest width.

Only a hint. A member that needs a wider slot still widens the run it lands in, and the reservation is then short, which costs one growth and no correctness.

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Intset, Malformed>

Read a blob written by us or by a real server.

The order check is the one worth having. A truncated blob is caught by the length arithmetic, but a blob whose members are out of order reads as a perfectly valid set that silently answers no to members it holds, because every search here assumes the order.

Source

pub fn as_bytes(&self) -> Option<&[u8]>

The blob, header included, ready to write to a file, when there is one.

None once the set has split, because Redis’s format is one array and carries nothing that could say otherwise. Nothing is lost by that: the split happens at RUN_MAX members, which is where a default configured server has already stopped storing the set as an intset, so a set that could have been written as one still is.

Source

pub const fn len(&self) -> usize

How many members.

Source

pub const fn is_empty(&self) -> bool

Whether there are none.

Source

pub fn runs(&self) -> usize

How many runs the members are spread over, which is one until the set passes RUN_MAX members.

Source

pub fn width(&self) -> usize

Bytes a member occupies in the widest run, which is 2, 4 or 8.

The widest and not one number for the set, because width is per run here. This is what a caller asking “how wide did this set have to get” means, and no search uses it.

It is the width of the stored offset and not of the value, so a set of integers around a billion reports two once it has split into runs. That is the point of the frame of reference the runs are packed against.

Source

pub fn byte_len(&self) -> usize

The bytes the members occupy, which is what MEMORY USAGE counts.

Source

pub fn memory_bytes(&self) -> usize

Bytes held, including whatever the vectors have reserved and not used.

Source

pub fn at(&self, index: usize) -> i64

The member at index, counting from the smallest.

§Panics

If index is not under Intset::len. Every caller here has already bounded it, and a draw for SRANDMEMBER bounds it by construction.

Source

pub fn get(&self, index: usize) -> Option<i64>

The member at index, or None past the end.

Source

pub fn min(&self) -> Option<i64>

The smallest member, or None if there are none.

Source

pub fn max(&self) -> Option<i64>

The largest member, or None if there are none.

Source

pub fn contains(&self, v: i64) -> bool

Whether v is a member.

Source

pub fn iter(&self) -> impl Iterator<Item = i64> + '_

Every member, smallest first.

Source

pub fn walk(&self) -> Walk<'_>

A cursor on the smallest member, for a merge. See Walk.

Source

pub fn add(&mut self, v: i64) -> bool

Add v. Answers whether it was not already there.

Source

pub fn remove(&mut self, v: i64) -> bool

Remove v. Answers whether it was there.

Trait Implementations§

Source§

impl Clone for Intset

Source§

fn clone(&self) -> Intset

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 Debug for Intset

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Intset

Source§

fn default() -> Intset

Returns the “default value” for a type. Read more
Source§

impl Eq for Intset

Source§

impl PartialEq for Intset

Two sets are equal when they hold the same members.

Written out rather than derived, because where the run boundaries fell is an artefact of the order the members arrived in and not something a caller has any business seeing. A set filled ascending and the same set filled scattered are the same set.

Source§

fn eq(&self, other: &Intset) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

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.