@@ -62,6 +62,8 @@ pub const ALL_INT_SCHEMES: &[&dyn IntegerScheme] = &[
6262 & RunEndScheme ,
6363 & SequenceScheme ,
6464 & RLE_INTEGER_SCHEME ,
65+ #[ cfg( feature = "pco" ) ]
66+ & PcoScheme ,
6567] ;
6668
6769/// [`Compressor`] for signed and unsigned integers.
@@ -156,6 +158,8 @@ pub enum IntCode {
156158 Sequence ,
157159 /// RLE encoding - generic run-length encoding.
158160 Rle ,
161+ /// Pco (pcodec) compression for integers.
162+ Pco ,
159163}
160164
161165#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
@@ -188,6 +192,11 @@ pub struct RunEndScheme;
188192#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
189193pub struct SequenceScheme ;
190194
195+ /// Pco (pcodec) compression for integers.
196+ #[ cfg( feature = "pco" ) ]
197+ #[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
198+ pub struct PcoScheme ;
199+
191200/// Threshold for the average run length in an array before we consider run-end encoding.
192201const RUN_END_THRESHOLD : u32 = 4 ;
193202
@@ -818,6 +827,49 @@ impl Scheme for SequenceScheme {
818827 }
819828}
820829
830+ #[ cfg( feature = "pco" ) ]
831+ impl Scheme for PcoScheme {
832+ type StatsType = IntegerStats ;
833+ type CodeType = IntCode ;
834+
835+ fn code ( & self ) -> IntCode {
836+ IntCode :: Pco
837+ }
838+
839+ fn expected_compression_ratio (
840+ & self ,
841+ compressor : & BtrBlocksCompressor ,
842+ stats : & Self :: StatsType ,
843+ ctx : CompressorContext ,
844+ excludes : & [ IntCode ] ,
845+ ) -> VortexResult < f64 > {
846+ // Pco does not support I8 or U8.
847+ if matches ! (
848+ stats. src. ptype( ) ,
849+ vortex_dtype:: PType :: I8 | vortex_dtype:: PType :: U8
850+ ) {
851+ return Ok ( 0.0 ) ;
852+ }
853+
854+ self . estimate_compression_ratio_with_sampling ( compressor, stats, ctx, excludes)
855+ }
856+
857+ fn compress (
858+ & self ,
859+ _compressor : & BtrBlocksCompressor ,
860+ stats : & Self :: StatsType ,
861+ _ctx : CompressorContext ,
862+ _excludes : & [ IntCode ] ,
863+ ) -> VortexResult < ArrayRef > {
864+ Ok ( vortex_pco:: PcoArray :: from_primitive (
865+ stats. source ( ) ,
866+ pco:: DEFAULT_COMPRESSION_LEVEL ,
867+ 8192 ,
868+ ) ?
869+ . into_array ( ) )
870+ }
871+ }
872+
821873#[ cfg( test) ]
822874mod tests {
823875 use std:: iter;
0 commit comments