@@ -33,13 +33,17 @@ use crate::cpc::compression::CompressedState;
3333use crate :: cpc:: count_bits_set_in_matrix;
3434use crate :: cpc:: determine_correct_offset;
3535use crate :: cpc:: determine_flavor;
36- use crate :: cpc:: estimator:: hip_confidence_lb;
37- use crate :: cpc:: estimator:: hip_confidence_ub;
38- use crate :: cpc:: estimator:: icon_confidence_lb;
39- use crate :: cpc:: estimator:: icon_confidence_ub;
40- use crate :: cpc:: estimator:: icon_estimate;
36+ use crate :: cpc:: estimator:: estimate;
37+ use crate :: cpc:: estimator:: lower_bound;
38+ use crate :: cpc:: estimator:: upper_bound;
4139use crate :: cpc:: kxp_byte_lookup:: KXP_BYTE_TABLE ;
4240use crate :: cpc:: pair_table:: PairTable ;
41+ use crate :: cpc:: serialization:: FLAG_COMPRESSED ;
42+ use crate :: cpc:: serialization:: FLAG_HAS_HIP ;
43+ use crate :: cpc:: serialization:: FLAG_HAS_TABLE ;
44+ use crate :: cpc:: serialization:: FLAG_HAS_WINDOW ;
45+ use crate :: cpc:: serialization:: SERIAL_VERSION ;
46+ use crate :: cpc:: serialization:: make_preamble_ints;
4347use crate :: error:: Error ;
4448use crate :: error:: ErrorKind ;
4549use crate :: hash:: DEFAULT_UPDATE_SEED ;
@@ -130,29 +134,34 @@ impl CpcSketch {
130134
131135 /// Returns the best estimate of the cardinality of the sketch.
132136 pub fn estimate ( & self ) -> f64 {
133- if !self . merge_flag {
134- self . hip_est_accum
135- } else {
136- icon_estimate ( self . lg_k , self . num_coupons )
137- }
137+ estimate (
138+ self . merge_flag ,
139+ self . hip_est_accum ,
140+ self . lg_k ,
141+ self . num_coupons ,
142+ )
138143 }
139144
140145 /// Returns the best estimate of the lower bound of the confidence interval given `kappa`.
141146 pub fn lower_bound ( & self , kappa : NumStdDev ) -> f64 {
142- if !self . merge_flag {
143- hip_confidence_lb ( self . lg_k , self . num_coupons , self . hip_est_accum , kappa)
144- } else {
145- icon_confidence_lb ( self . lg_k , self . num_coupons , kappa)
146- }
147+ lower_bound (
148+ self . merge_flag ,
149+ self . hip_est_accum ,
150+ self . lg_k ,
151+ self . num_coupons ,
152+ kappa,
153+ )
147154 }
148155
149156 /// Returns the best estimate of the upper bound of the confidence interval given `kappa`.
150157 pub fn upper_bound ( & self , kappa : NumStdDev ) -> f64 {
151- if !self . merge_flag {
152- hip_confidence_ub ( self . lg_k , self . num_coupons , self . hip_est_accum , kappa)
153- } else {
154- icon_confidence_ub ( self . lg_k , self . num_coupons , kappa)
155- }
158+ upper_bound (
159+ self . merge_flag ,
160+ self . hip_est_accum ,
161+ self . lg_k ,
162+ self . num_coupons ,
163+ kappa,
164+ )
156165 }
157166
158167 /// Returns true if the sketch is empty.
@@ -437,12 +446,6 @@ impl CpcSketch {
437446 }
438447}
439448
440- const SERIAL_VERSION : u8 = 1 ;
441- const FLAG_COMPRESSED : u8 = 1 ;
442- const FLAG_HAS_HIP : u8 = 2 ;
443- const FLAG_HAS_TABLE : u8 = 3 ;
444- const FLAG_HAS_WINDOW : u8 = 4 ;
445-
446449impl CpcSketch {
447450 /// Serializes this CpcSketch to bytes.
448451 pub fn serialize ( & self ) -> Vec < u8 > {
@@ -637,27 +640,6 @@ impl CpcSketch {
637640 }
638641}
639642
640- fn make_preamble_ints ( num_coupons : u32 , has_hip : bool , has_table : bool , has_window : bool ) -> u8 {
641- let mut preamble_ints = 2 ;
642- if num_coupons > 0 {
643- preamble_ints += 1 ; // number of coupons
644- if has_hip {
645- preamble_ints += 4 ; // HIP
646- }
647- if has_table {
648- preamble_ints += 1 ; // table data length
649- // number of values (if there is no window it is the same as number of coupons)
650- if has_window {
651- preamble_ints += 1 ;
652- }
653- }
654- if has_window {
655- preamble_ints += 1 ; // window length
656- }
657- }
658- preamble_ints
659- }
660-
661643impl CpcSketch {
662644 /// Returns the estimated maximum compressed serialized size of a sketch.
663645 ///
0 commit comments