@@ -217,6 +217,64 @@ impl Chunk {
217
217
} )
218
218
. collect ( )
219
219
}
220
+
221
+ /// Computes the `RowId` range covered by each individual component column on each timeline.
222
+ ///
223
+ /// This is different from the `RowId` range covered by the [`Chunk`] as a whole because component
224
+ /// columns are potentially sparse.
225
+ ///
226
+ /// This is crucial for indexing and queries to work properly.
227
+ //
228
+ // TODO(cmc): This needs to be stored in chunk metadata and transported across IPC.
229
+ pub fn row_id_range_per_component ( & self ) -> BTreeMap < ComponentName , ( RowId , RowId ) > {
230
+ re_tracing:: profile_function!( ) ;
231
+
232
+ let row_ids = self . row_ids ( ) . collect_vec ( ) ;
233
+
234
+ if self . is_sorted ( ) {
235
+ self . components
236
+ . iter ( )
237
+ . filter_map ( |( component_name, list_array) | {
238
+ let mut row_id_min = None ;
239
+ let mut row_id_max = None ;
240
+
241
+ for ( i, & row_id) in row_ids. iter ( ) . enumerate ( ) {
242
+ if list_array. is_valid ( i) {
243
+ row_id_min = Some ( row_id) ;
244
+ }
245
+ }
246
+ for ( i, & row_id) in row_ids. iter ( ) . enumerate ( ) . rev ( ) {
247
+ if list_array. is_valid ( i) {
248
+ row_id_max = Some ( row_id) ;
249
+ }
250
+ }
251
+
252
+ Some ( ( * component_name, ( row_id_min?, row_id_max?) ) )
253
+ } )
254
+ . collect ( )
255
+ } else {
256
+ self . components
257
+ . iter ( )
258
+ . filter_map ( |( component_name, list_array) | {
259
+ let mut row_id_min = Some ( RowId :: MAX ) ;
260
+ let mut row_id_max = Some ( RowId :: ZERO ) ;
261
+
262
+ for ( i, & row_id) in row_ids. iter ( ) . enumerate ( ) {
263
+ if list_array. is_valid ( i) && Some ( row_id) > row_id_min {
264
+ row_id_min = Some ( row_id) ;
265
+ }
266
+ }
267
+ for ( i, & row_id) in row_ids. iter ( ) . enumerate ( ) . rev ( ) {
268
+ if list_array. is_valid ( i) && Some ( row_id) < row_id_max {
269
+ row_id_max = Some ( row_id) ;
270
+ }
271
+ }
272
+
273
+ Some ( ( * component_name, ( row_id_min?, row_id_max?) ) )
274
+ } )
275
+ . collect ( )
276
+ }
277
+ }
220
278
}
221
279
222
280
// ---
0 commit comments