pub struct Intset { /* private fields */ }Expand description
A sorted packed set of integers, in one or more runs.
Implementations§
Source§impl Intset
impl Intset
Sourcepub fn with_capacity(n: usize) -> Intset
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.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Intset, Malformed>
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.
Sourcepub fn as_bytes(&self) -> Option<&[u8]>
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.
Sourcepub fn runs(&self) -> usize
pub fn runs(&self) -> usize
How many runs the members are spread over, which is one until the set
passes RUN_MAX members.
Sourcepub fn width(&self) -> usize
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.
Sourcepub fn byte_len(&self) -> usize
pub fn byte_len(&self) -> usize
The bytes the members occupy, which is what MEMORY USAGE counts.
Sourcepub fn memory_bytes(&self) -> usize
pub fn memory_bytes(&self) -> usize
Bytes held, including whatever the vectors have reserved and not used.
Trait Implementations§
impl Eq for Intset
Source§impl PartialEq for Intset
Two sets are equal when they hold the same members.
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.