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

Method read_tile_as_of

nodedb-array/src/segment/reader.rs:182–213  ·  view source on GitHub ↗

Reverse-scan tile entries with the given `hilbert_prefix` and `system_from_ms <= system_as_of`, returning the newest qualifying tile version. Returns `Ok(None)` if no version exists at or before the cutoff. The `valid_at_ms` parameter is reserved for the query layer (Tier 9.2). At the reader level, valid-time filtering is NOT applied — the whole tile is returned. This keeps the reader cell-shape

(
        &self,
        hilbert_prefix: u64,
        system_as_of: i64,
        _valid_at_ms: Option<i64>,
    )

Source from the content-addressed store, hash-verified

180 /// 9.2). At the reader level, valid-time filtering is NOT applied —
181 /// the whole tile is returned. This keeps the reader cell-shape-agnostic.
182 pub fn read_tile_as_of(
183 &self,
184 hilbert_prefix: u64,
185 system_as_of: i64,
186 _valid_at_ms: Option<i64>,
187 ) -> ArrayResult<Option<TilePayload>> {
188 let tiles = &self.footer.tiles;
189
190 // Binary search for the first entry with hilbert_prefix.
191 let first = tiles.partition_point(|e| e.tile_id.hilbert_prefix < hilbert_prefix);
192 // Binary search for the first entry past the range:
193 // hilbert_prefix matches and system_from_ms <= system_as_of.
194 // Upper bound: first entry where prefix > hilbert_prefix.
195 let past_prefix = tiles.partition_point(|e| e.tile_id.hilbert_prefix <= hilbert_prefix);
196
197 // Slice of entries with matching prefix.
198 let candidates = &tiles[first..past_prefix];
199 if candidates.is_empty() {
200 return Ok(None);
201 }
202
203 // Within the prefix slice, entries are ordered by system_from_ms ascending.
204 // Find the rightmost entry with system_from_ms <= system_as_of.
205 let cutoff_pos = candidates.partition_point(|e| e.tile_id.system_from_ms <= system_as_of);
206 if cutoff_pos == 0 {
207 return Ok(None);
208 }
209
210 // The entry at cutoff_pos - 1 is the newest qualifying version.
211 let entry_idx = first + cutoff_pos - 1;
212 self.read_tile(entry_idx).map(Some)
213 }
214
215 /// Returns an iterator over all tile versions for `hilbert_prefix` whose
216 /// `system_from_ms <= system_as_of`, ordered **newest-first** by

Calls 2

read_tileMethod · 0.80
is_emptyMethod · 0.45