@@ -507,3 +507,81 @@ pub(crate) fn slice_and_maybe_filter(
507507 Ok ( sliced_arrays)
508508 }
509509}
510+
511+ /// Blocked style group index used in blocked mode group values and accumulators
512+ /// - High 32 bits represent `block_id`
513+ /// - Low 32 bits represent `block_offset`
514+ ///
515+ pub trait GroupIndexOperations {
516+ fn pack_index ( block_id : u32 , block_offset : u64 ) -> u64 ;
517+
518+ fn get_block_id ( packed_index : u64 ) -> u32 ;
519+
520+ fn get_block_offset ( packed_index : u64 ) -> u64 ;
521+ }
522+
523+ pub struct BlockedGroupIndexOperations ;
524+
525+ impl GroupIndexOperations for BlockedGroupIndexOperations {
526+ fn pack_index ( block_id : u32 , block_offset : u64 ) -> u64 {
527+ ( ( block_id as u64 ) << 32 ) | block_offset
528+ }
529+
530+ fn get_block_id ( packed_index : u64 ) -> u32 {
531+ ( packed_index >> 32 ) as u32
532+ }
533+
534+ fn get_block_offset ( packed_index : u64 ) -> u64 {
535+ ( packed_index as u32 ) as u64
536+ }
537+ }
538+
539+ pub struct FlatGroupIndexOperations ;
540+
541+ impl GroupIndexOperations for FlatGroupIndexOperations {
542+ fn pack_index ( _block_id : u32 , block_offset : u64 ) -> u64 {
543+ block_offset
544+ }
545+
546+ fn get_block_id ( _packed_index : u64 ) -> u32 {
547+ 0
548+ }
549+
550+ fn get_block_offset ( packed_index : u64 ) -> u64 {
551+ packed_index
552+ }
553+ }
554+
555+ // #[cfg(test)]
556+ // mod tests {
557+ // use super::*;
558+
559+ // #[test]
560+ // fn test_blocked_group_index_build() {
561+ // let group_index1 = 1;
562+ // let group_index2 = (42_u64 << 32) | 2;
563+ // let group_index3 = ((u32::MAX as u64) << 32) | 3;
564+
565+ // let index_builder = BlockedGroupIndexBuilder::new(false);
566+ // let flat1 = index_builder.build(group_index1 as usize);
567+ // let flat2 = index_builder.build(group_index2 as usize);
568+ // let flat3 = index_builder.build(group_index3 as usize);
569+ // let expected1 = BlockedGroupIndex::new_from_parts(0, group_index1);
570+ // let expected2 = BlockedGroupIndex::new_from_parts(0, group_index2);
571+ // let expected3 = BlockedGroupIndex::new_from_parts(0, group_index3);
572+ // assert_eq!(flat1, expected1);
573+ // assert_eq!(flat2, expected2);
574+ // assert_eq!(flat3, expected3);
575+
576+ // let index_builder = BlockedGroupIndexBuilder::new(true);
577+ // let blocked1 = index_builder.build(group_index1 as usize);
578+ // let blocked2 = index_builder.build(group_index2 as usize);
579+ // let blocked3 = index_builder.build(group_index3 as usize);
580+ // let expected1 = BlockedGroupIndex::new_from_parts(0, 1);
581+ // let expected2 = BlockedGroupIndex::new_from_parts(42, 2);
582+ // let expected3 = BlockedGroupIndex::new_from_parts(u32::MAX, 3);
583+ // assert_eq!(blocked1, expected1);
584+ // assert_eq!(blocked2, expected2);
585+ // assert_eq!(blocked3, expected3);
586+ // }
587+ // }
0 commit comments