@@ -10,6 +10,16 @@ use crate::rust::cursor::IncrementCursor;
1010use crate :: rust:: integer_compression:: { bitpacking, bitunpacking} ;
1111use crate :: { BlockCodec , FastPForError , FastPForResult } ;
1212
13+ mod sealed {
14+ /// Sealed marker trait: only `[u32; 128]` and `[u32; 256]` are valid `FastPFor` block arrays.
15+ ///
16+ /// This is intentionally private so that users cannot implement it for other sizes,
17+ /// preventing instantiation of `FastPFor<N>` for unsupported `N` at compile time.
18+ pub trait BlockSize : bytemuck:: Pod { }
19+ impl BlockSize for [ u32 ; 128 ] { }
20+ impl BlockSize for [ u32 ; 256 ] { }
21+ }
22+
1323/// Overhead cost (in bits) for storing each exception's position in the block
1424const OVERHEAD_OF_EACH_EXCEPT : u32 = 8 ;
1525
@@ -63,36 +73,20 @@ pub struct FastPFor<const N: usize> {
6373
6474impl < const N : usize > Default for FastPFor < N >
6575where
66- [ u32 ; N ] : bytemuck :: Pod ,
76+ [ u32 ; N ] : sealed :: BlockSize ,
6777{
6878 fn default ( ) -> Self {
69- Self :: create ( DEFAULT_PAGE_SIZE )
79+ Self :: new ( DEFAULT_PAGE_SIZE )
7080 . expect ( "DEFAULT_PAGE_SIZE is a multiple of all valid block sizes" )
7181 }
7282}
7383
74- impl FastPFor < 128 > {
75- /// Creates a new `FastPForBlock128` codec with the given page size.
84+ impl < const N : usize > FastPFor < N > {
85+ /// Creates a new `FastPForBlock` with a codec with the given page size.
7686 ///
7787 /// Returns an error if `page_size` is not a multiple of 128.
7888 /// Use [`Default`] for the default page size.
7989 pub fn new ( page_size : u32 ) -> FastPForResult < Self > {
80- Self :: create ( page_size)
81- }
82- }
83-
84- impl FastPFor < 256 > {
85- /// Creates a new `FastPForBlock256` codec with the given page size.
86- ///
87- /// Returns an error if `page_size` is not a multiple of 256.
88- /// Use [`Default`] for the default page size.
89- pub fn new ( page_size : u32 ) -> FastPForResult < Self > {
90- Self :: create ( page_size)
91- }
92- }
93-
94- impl < const N : usize > FastPFor < N > {
95- fn create ( page_size : u32 ) -> FastPForResult < Self > {
9690 if page_size % N as u32 != 0 {
9791 return Err ( FastPForError :: InvalidPageSize {
9892 page_size,
@@ -499,7 +493,7 @@ impl<const N: usize> FastPFor<N> {
499493
500494impl < const N : usize > BlockCodec for FastPFor < N >
501495where
502- [ u32 ; N ] : bytemuck :: Pod ,
496+ [ u32 ; N ] : sealed :: BlockSize ,
503497{
504498 type Block = [ u32 ; N ] ;
505499
0 commit comments