@@ -85,14 +85,30 @@ impl SuffixArray {
8585 }
8686
8787 /// Issues a non-blocking hardware prefetch hint for the cache line holding SA entry `index`.
88- #[ cfg( feature = "mmap" ) ]
8988 #[ inline]
9089 pub fn prefetch_sa_index ( & self , index : usize ) {
91- if let SuffixArray :: MmapBacked { mmap, data_offset, bits_per_value, .. } = self {
92- let byte_offset = data_offset + ( index * bits_per_value) / 8 ;
93- if byte_offset < mmap. len ( ) {
94- let ptr: * const u8 = & mmap[ byte_offset] ;
95- prefetch:: prefetch_read ( ptr) ;
90+ match self {
91+ SuffixArray :: Original ( sa, _) => {
92+ if index < sa. len ( ) {
93+ prefetch:: prefetch_read ( unsafe { sa. as_ptr ( ) . add ( index) as * const u8 } ) ;
94+ }
95+ }
96+ SuffixArray :: Compressed ( ba, _) => {
97+ let bpv = ba. bits_per_value ( ) ;
98+ let word_idx = ( index * bpv) / 64 ;
99+ let total_words = ( ba. len ( ) * bpv + 63 ) / 64 ;
100+ if word_idx < total_words {
101+ let ptr = ba. get_data_slice ( word_idx, word_idx + 1 ) . as_ptr ( ) as * const u8 ;
102+ prefetch:: prefetch_read ( ptr) ;
103+ }
104+ }
105+ #[ cfg( feature = "mmap" ) ]
106+ SuffixArray :: MmapBacked { mmap, data_offset, bits_per_value, .. } => {
107+ let byte_offset = data_offset + ( index * bits_per_value) / 8 ;
108+ if byte_offset < mmap. len ( ) {
109+ let ptr: * const u8 = & mmap[ byte_offset] ;
110+ prefetch:: prefetch_read ( ptr) ;
111+ }
96112 }
97113 }
98114 }
0 commit comments