@@ -423,6 +423,43 @@ impl TableCollection {
423423 handle_tsk_return_value ! ( rv)
424424 }
425425
426+ /// Return `true` if tables are indexed.
427+ pub fn is_indexed ( & self ) -> bool {
428+ unsafe { ll_bindings:: tsk_table_collection_has_index ( self . as_ptr ( ) , 0 ) }
429+ }
430+
431+ /// If `self.is_indexed()` is `true`, return a non-owning
432+ /// slice containing the edge insertion order.
433+ /// Otherwise, return `None`.
434+ pub fn edge_insertion_order ( & self ) -> Option < & [ tsk_id_t ] > {
435+ if self . is_indexed ( ) {
436+ Some ( unsafe {
437+ std:: slice:: from_raw_parts (
438+ ( * self . as_ptr ( ) ) . indexes . edge_insertion_order ,
439+ ( * self . as_ptr ( ) ) . indexes . num_edges as usize ,
440+ )
441+ } )
442+ } else {
443+ None
444+ }
445+ }
446+
447+ /// If `self.is_indexed()` is `true`, return a non-owning
448+ /// slice containing the edge removal order.
449+ /// Otherwise, return `None`.
450+ pub fn edge_removal_order ( & self ) -> Option < & [ tsk_id_t ] > {
451+ if self . is_indexed ( ) {
452+ Some ( unsafe {
453+ std:: slice:: from_raw_parts (
454+ ( * self . as_ptr ( ) ) . indexes . edge_removal_order ,
455+ ( * self . as_ptr ( ) ) . indexes . num_edges as usize ,
456+ )
457+ } )
458+ } else {
459+ None
460+ }
461+ }
462+
426463 /// Sort the tables.
427464 /// The [``bookmark``](crate::types::Bookmark) can
428465 /// be used to affect where sorting starts from for each table.
@@ -716,6 +753,30 @@ mod test {
716753 }
717754 }
718755
756+ #[ test]
757+ fn test_edge_index_access ( ) {
758+ let tables = make_small_table_collection ( ) ;
759+ assert_eq ! ( tables. is_indexed( ) , true ) ;
760+ assert_eq ! (
761+ tables. edge_insertion_order( ) . unwrap( ) . len( ) ,
762+ tables. edges( ) . num_rows( ) as usize
763+ ) ;
764+ assert_eq ! (
765+ tables. edge_removal_order( ) . unwrap( ) . len( ) ,
766+ tables. edges( ) . num_rows( ) as usize
767+ ) ;
768+
769+ for i in tables. edge_insertion_order ( ) . unwrap ( ) {
770+ assert ! ( * i >= 0 ) ;
771+ assert ! ( * i < tables. edges( ) . num_rows( ) as tsk_id_t) ;
772+ }
773+
774+ for i in tables. edge_removal_order ( ) . unwrap ( ) {
775+ assert ! ( * i >= 0 ) ;
776+ assert ! ( * i < tables. edges( ) . num_rows( ) as tsk_id_t) ;
777+ }
778+ }
779+
719780 #[ test]
720781 fn test_add_site ( ) {
721782 let mut tables = TableCollection :: new ( 1000. ) . unwrap ( ) ;
0 commit comments