MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / outlier_at

Method outlier_at

nodedb-codec/src/vector_quant/layout.rs:244–262  ·  view source on GitHub ↗

Return the outlier `(dim_index, value)` for the dimension at position `slot` in the bitmask. `slot` is the dimension index (0–63). Returns `None` if the bit for `slot` is not set in `outlier_bitmask`, or if `slot ≥ 64`. Uses a branchless popcnt to find the dense offset into the outlier payload.

(&self, slot: u32)

Source from the content-addressed store, hash-verified

242 /// Uses a branchless popcnt to find the dense offset into the outlier
243 /// payload.
244 pub fn outlier_at(&self, slot: u32) -> Option<(u32, f32)> {
245 if slot >= 64 {
246 return None;
247 }
248 let bitmask = self.header().outlier_bitmask;
249 if bitmask & (1u64 << slot) == 0 {
250 return None;
251 }
252 // Number of set bits below `slot` gives the dense array index.
253 let mask = bitmask & ((1u64 << slot).wrapping_sub(1));
254 let offset = mask.count_ones() as usize;
255
256 let header_bytes = core::mem::size_of::<QuantHeader>();
257 let base = header_bytes + self.packed_bits_len + offset * OUTLIER_ENTRY_BYTES;
258
259 let dim_idx = u32::from_le_bytes(self.buf[base..base + 4].try_into().ok()?);
260 let value = f32::from_le_bytes(self.buf[base + 4..base + 8].try_into().ok()?);
261 Some((dim_idx, value))
262 }
263
264 /// Full backing buffer suitable for direct I/O.
265 #[inline]

Callers 4

one_outlier_roundtripFunction · 0.80
eight_outliers_roundtripFunction · 0.80
outlier_ordering_popcntFunction · 0.80

Calls 3

count_onesMethod · 0.80
headerMethod · 0.45
okMethod · 0.45

Tested by 4

one_outlier_roundtripFunction · 0.64
eight_outliers_roundtripFunction · 0.64
outlier_ordering_popcntFunction · 0.64