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>
impl<'a> OrdinalSpace<'a>
Sourcepub fn new(raw: &'a [u8], oid_len: usize) -> Self
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.
pub fn is_empty(&self) -> bool
Sourcepub fn oid(&self, ordinal: u32) -> Option<&'a [u8]>
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.
Sourcepub fn ordinal_of_raw(&self, oid: &[u8]) -> Option<u32>
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.
Sourcepub fn ordinal_of_hex(&self, hex: &str) -> Option<u32>
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.