@@ -123,93 +123,6 @@ pub struct MaskValues {
123123 density : f64 ,
124124}
125125
126- impl MaskValues {
127- /// Returns the length of the mask.
128- #[ inline]
129- pub fn len ( & self ) -> usize {
130- self . buffer . len ( )
131- }
132-
133- /// Returns true if the mask is empty i.e., it's length is 0.
134- #[ inline]
135- pub fn is_empty ( & self ) -> bool {
136- self . buffer . is_empty ( )
137- }
138-
139- /// Returns the true count of the mask.
140- #[ inline]
141- pub fn true_count ( & self ) -> usize {
142- self . true_count
143- }
144-
145- /// Returns the boolean buffer representation of the mask.
146- #[ inline]
147- pub fn bit_buffer ( & self ) -> & BitBuffer {
148- & self . buffer
149- }
150-
151- /// Returns the boolean value at a given index.
152- #[ inline]
153- pub fn value ( & self , index : usize ) -> bool {
154- self . buffer . value ( index)
155- }
156-
157- /// Constructs an indices vector from one of the other representations.
158- pub fn indices ( & self ) -> & [ usize ] {
159- self . indices . get_or_init ( || {
160- if self . true_count == 0 {
161- return vec ! [ ] ;
162- }
163-
164- if self . true_count == self . len ( ) {
165- return ( 0 ..self . len ( ) ) . collect ( ) ;
166- }
167-
168- if let Some ( slices) = self . slices . get ( ) {
169- let mut indices = Vec :: with_capacity ( self . true_count ) ;
170- indices. extend ( slices. iter ( ) . flat_map ( |( start, end) | * start..* end) ) ;
171- debug_assert ! ( indices. is_sorted( ) ) ;
172- assert_eq ! ( indices. len( ) , self . true_count) ;
173- return indices;
174- }
175-
176- let mut indices = Vec :: with_capacity ( self . true_count ) ;
177- indices. extend ( self . buffer . set_indices ( ) ) ;
178- debug_assert ! ( indices. is_sorted( ) ) ;
179- assert_eq ! ( indices. len( ) , self . true_count) ;
180- indices
181- } )
182- }
183-
184- /// Constructs a slices vector from one of the other representations.
185- #[ allow( clippy:: cast_possible_truncation) ]
186- #[ inline]
187- pub fn slices ( & self ) -> & [ ( usize , usize ) ] {
188- self . slices . get_or_init ( || {
189- if self . true_count == self . len ( ) {
190- return vec ! [ ( 0 , self . len( ) ) ] ;
191- }
192-
193- self . buffer . set_slices ( ) . collect ( )
194- } )
195- }
196-
197- /// Return an iterator over either indices or slices of the mask based on a density threshold.
198- #[ inline]
199- pub fn threshold_iter ( & self , threshold : f64 ) -> MaskIter < ' _ > {
200- if self . density >= threshold {
201- MaskIter :: Slices ( self . slices ( ) )
202- } else {
203- MaskIter :: Indices ( self . indices ( ) )
204- }
205- }
206-
207- /// Extracts the internal [`BitBuffer`].
208- pub ( crate ) fn into_buffer ( self ) -> BitBuffer {
209- self . buffer
210- }
211- }
212-
213126impl Mask {
214127 /// Create a new Mask where all values are set.
215128 #[ inline]
@@ -642,6 +555,93 @@ impl Mask {
642555 }
643556}
644557
558+ impl MaskValues {
559+ /// Returns the length of the mask.
560+ #[ inline]
561+ pub fn len ( & self ) -> usize {
562+ self . buffer . len ( )
563+ }
564+
565+ /// Returns true if the mask is empty i.e., it's length is 0.
566+ #[ inline]
567+ pub fn is_empty ( & self ) -> bool {
568+ self . buffer . is_empty ( )
569+ }
570+
571+ /// Returns the true count of the mask.
572+ #[ inline]
573+ pub fn true_count ( & self ) -> usize {
574+ self . true_count
575+ }
576+
577+ /// Returns the boolean buffer representation of the mask.
578+ #[ inline]
579+ pub fn bit_buffer ( & self ) -> & BitBuffer {
580+ & self . buffer
581+ }
582+
583+ /// Returns the boolean value at a given index.
584+ #[ inline]
585+ pub fn value ( & self , index : usize ) -> bool {
586+ self . buffer . value ( index)
587+ }
588+
589+ /// Constructs an indices vector from one of the other representations.
590+ pub fn indices ( & self ) -> & [ usize ] {
591+ self . indices . get_or_init ( || {
592+ if self . true_count == 0 {
593+ return vec ! [ ] ;
594+ }
595+
596+ if self . true_count == self . len ( ) {
597+ return ( 0 ..self . len ( ) ) . collect ( ) ;
598+ }
599+
600+ if let Some ( slices) = self . slices . get ( ) {
601+ let mut indices = Vec :: with_capacity ( self . true_count ) ;
602+ indices. extend ( slices. iter ( ) . flat_map ( |( start, end) | * start..* end) ) ;
603+ debug_assert ! ( indices. is_sorted( ) ) ;
604+ assert_eq ! ( indices. len( ) , self . true_count) ;
605+ return indices;
606+ }
607+
608+ let mut indices = Vec :: with_capacity ( self . true_count ) ;
609+ indices. extend ( self . buffer . set_indices ( ) ) ;
610+ debug_assert ! ( indices. is_sorted( ) ) ;
611+ assert_eq ! ( indices. len( ) , self . true_count) ;
612+ indices
613+ } )
614+ }
615+
616+ /// Constructs a slices vector from one of the other representations.
617+ #[ allow( clippy:: cast_possible_truncation) ]
618+ #[ inline]
619+ pub fn slices ( & self ) -> & [ ( usize , usize ) ] {
620+ self . slices . get_or_init ( || {
621+ if self . true_count == self . len ( ) {
622+ return vec ! [ ( 0 , self . len( ) ) ] ;
623+ }
624+
625+ self . buffer . set_slices ( ) . collect ( )
626+ } )
627+ }
628+
629+ /// Return an iterator over either indices or slices of the mask based on a density threshold.
630+ #[ inline]
631+ pub fn threshold_iter ( & self , threshold : f64 ) -> MaskIter < ' _ > {
632+ if self . density >= threshold {
633+ MaskIter :: Slices ( self . slices ( ) )
634+ } else {
635+ MaskIter :: Indices ( self . indices ( ) )
636+ }
637+ }
638+
639+ /// Extracts the internal [`BitBuffer`].
640+ pub ( crate ) fn into_buffer ( self ) -> BitBuffer {
641+ self . buffer
642+ }
643+ }
644+
645645/// Iterator over the indices or slices of a mask.
646646pub enum MaskIter < ' a > {
647647 /// Slice of pre-cached indices of a mask.
0 commit comments