File tree Expand file tree Collapse file tree
vortex-array/src/aggregate_fn/fns/is_sorted Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+ // SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+ use vortex_error:: VortexResult ;
5+ use vortex_mask:: Mask ;
6+
7+ use super :: IsSortedIteratorExt ;
8+ use crate :: arrays:: BoolArray ;
9+
10+ pub ( super ) fn check_bool_sorted ( array : & BoolArray , strict : bool ) -> VortexResult < bool > {
11+ match array. validity_mask ( ) ? {
12+ Mask :: AllFalse ( _) => Ok ( !strict) ,
13+ Mask :: AllTrue ( _) => {
14+ let values = array. to_bit_buffer ( ) ;
15+ Ok ( if strict {
16+ values. iter ( ) . is_strict_sorted ( )
17+ } else {
18+ values. iter ( ) . is_sorted ( )
19+ } )
20+ }
21+ Mask :: Values ( mask_values) => {
22+ if strict {
23+ let validity_buffer = mask_values. bit_buffer ( ) ;
24+ let values = array. to_bit_buffer ( ) ;
25+ Ok ( validity_buffer
26+ . iter ( )
27+ . zip ( values. iter ( ) )
28+ . map ( |( is_valid, value) | is_valid. then_some ( value) )
29+ . is_strict_sorted ( ) )
30+ } else {
31+ let set_indices = mask_values. bit_buffer ( ) . set_indices ( ) ;
32+ let values = array. to_bit_buffer ( ) ;
33+ let values_iter = set_indices. map ( |idx|
34+ // Safety:
35+ // All idxs are in-bounds for the array.
36+ unsafe {
37+ values. value_unchecked ( idx)
38+ } ) ;
39+ Ok ( values_iter. is_sorted ( ) )
40+ }
41+ }
42+ }
43+ }
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+ // SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+ use itertools:: Itertools ;
5+ use vortex_error:: VortexResult ;
6+ use vortex_mask:: Mask ;
7+
8+ use super :: IsSortedIteratorExt ;
9+ use crate :: arrays:: DecimalArray ;
10+ use crate :: dtype:: NativeDecimalType ;
11+ use crate :: match_each_decimal_value_type;
12+
13+ pub ( super ) fn check_decimal_sorted ( array : & DecimalArray , strict : bool ) -> VortexResult < bool > {
14+ match_each_decimal_value_type ! ( array. values_type( ) , |S | {
15+ compute_is_sorted:: <S >( array, strict)
16+ } )
17+ }
18+
19+ fn compute_is_sorted < T : NativeDecimalType > ( array : & DecimalArray , strict : bool ) -> VortexResult < bool >
20+ where
21+ dyn Iterator < Item = T > : IsSortedIteratorExt ,
22+ {
23+ match array. validity_mask ( ) ? {
24+ Mask :: AllFalse ( _) => Ok ( !strict) ,
25+ Mask :: AllTrue ( _) => {
26+ let buf = array. buffer :: < T > ( ) ;
27+ let iter = buf. iter ( ) . copied ( ) ;
28+
29+ Ok ( if strict {
30+ IsSortedIteratorExt :: is_strict_sorted ( iter)
31+ } else {
32+ iter. is_sorted ( )
33+ } )
34+ }
35+ Mask :: Values ( mask_values) => {
36+ let values = array. buffer :: < T > ( ) ;
37+ let iter = mask_values
38+ . bit_buffer ( )
39+ . iter ( )
40+ . zip_eq ( values)
41+ . map ( |( is_valid, v) | is_valid. then_some ( v) ) ;
42+
43+ Ok ( if strict {
44+ IsSortedIteratorExt :: is_strict_sorted ( iter)
45+ } else {
46+ iter. is_sorted ( )
47+ } )
48+ }
49+ }
50+ }
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+ // SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+ use vortex_error:: VortexResult ;
5+
6+ use crate :: ExecutionCtx ;
7+ use crate :: arrays:: ExtensionArray ;
8+
9+ pub ( super ) fn check_extension_sorted (
10+ array : & ExtensionArray ,
11+ strict : bool ,
12+ ctx : & mut ExecutionCtx ,
13+ ) -> VortexResult < bool > {
14+ if strict {
15+ super :: is_strict_sorted ( array. storage_array ( ) , ctx)
16+ } else {
17+ super :: is_sorted ( array. storage_array ( ) , ctx)
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments