Skip to main content

OrdinalSpace

Struct OrdinalSpace 

Source
pub struct OrdinalSpace<'a> { /* private fields */ }
Expand description

oid → ordinal, and ordinal → oid, over one flat buffer and nothing else.

The ordinal space is oids_raw — every distinct oid in the archive, fixed-width and back to back, in oid-lexicographic (= raw byte) order, which is exactly the order the ordinal numbers it. Because that buffer is already sorted and already the inverse map (ordinal o is the slice at o * oid_len), both directions are answered from it:

  • ordinal_of_raw / ordinal_of_hex — a binary search over the buffer, O(log n) with no probe table to keep in step with it;
  • oid — a slice.

This is what replaced Derived::oids (a hex Vec<String>) and Derived::ordinal (a HashMap<String, u32>) — two per-oid String allocations, built at every fold, that a comment then had to promise agreed with the flat buffer. One representation, no promise needed (LAW 5). It owns nothing: it is a Copy view (&[u8] + a length), so constructing it at open allocates zero bytes.

Implementations§

Source§

impl<'a> OrdinalSpace<'a>

Source

pub fn new(raw: &'a [u8], oid_len: usize) -> Self

Borrow a flat, sorted, fixed-width oid buffer as the ordinal space. The sort is the caller’s invariant (every builder produces it in oid-lexicographic order); the binary search below rests on it.

Source

pub fn len(&self) -> usize

How many oids the space holds.

Source

pub fn is_empty(&self) -> bool

Source

pub fn oid(&self, ordinal: u32) -> Option<&'a [u8]>

ordinal → raw oid, a slice into the flat buffer. None for an ordinal outside the space.

Source

pub fn ordinal_of_raw(&self, oid: &[u8]) -> Option<u32>

raw oid → ordinal, by binary search over the sorted flat buffer.

This is the exact inverse of Self::oid: the buffer is sorted, so the index a search lands on IS the ordinal, and it equals what the old HashMap<String, u32> returned for the same oid — that map keyed the same sorted list by its own hex spelling.

Source

pub fn ordinal_of_hex(&self, hex: &str) -> Option<u32>

hex oid → ordinal. Decodes the hex into a stack buffer (≤ 32 bytes), so a lookup allocates nothing, then binary-searches the raw form. A hex string that is the wrong length or not hex is simply absent.

Trait Implementations§

Source§

impl<'a> Clone for OrdinalSpace<'a>

Source§

fn clone(&self) -> Self

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 OrdinalSpace<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for OrdinalSpace<'a>

§

impl<'a> RefUnwindSafe for OrdinalSpace<'a>

§

impl<'a> Send for OrdinalSpace<'a>

§

impl<'a> Sync for OrdinalSpace<'a>

§

impl<'a> Unpin for OrdinalSpace<'a>

§

impl<'a> UnsafeUnpin for OrdinalSpace<'a>

§

impl<'a> UnwindSafe for OrdinalSpace<'a>

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more