1 //------------------------------------------------------------------------------
2 // GB_qsort_3: sort a 3-by-n list of integers, using A[0:2][] as the key
3 //------------------------------------------------------------------------------
4 
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7 
8 //------------------------------------------------------------------------------
9 
10 #include "GB_sort.h"
11 
12 // returns true if A [a] < B [b]
13 #define GB_lt(A,a,B,b)                  \
14     GB_lt_3 (A ## _0, A ## _1, A ## _2, a, B ## _0, B ## _1, B ## _2, b)
15 
16 // argument list for calling a function
17 #define GB_arg(A)                       \
18     A ## _0, A ## _1, A ## _2
19 
20 // argument list for calling a function, with offset
21 #define GB_arg_offset(A,x)              \
22     A ## _0 + (x), A ## _1 + (x), A ## _2 + (x)
23 
24 // argument list for defining a function
25 #define GB_args(A)                      \
26     int64_t *restrict A ## _0,          \
27     int64_t *restrict A ## _1,          \
28     int64_t *restrict A ## _2
29 
30 // each entry has a 3-integer key
31 #define GB_K 3
32 
33 // swap A [a] and A [b]
34 #define GB_swap(A,a,b)                                                        \
35 {                                                                             \
36     int64_t t0 = A ## _0 [a] ; A ## _0 [a] = A ## _0 [b] ; A ## _0 [b] = t0 ; \
37     int64_t t1 = A ## _1 [a] ; A ## _1 [a] = A ## _1 [b] ; A ## _1 [b] = t1 ; \
38     int64_t t2 = A ## _2 [a] ; A ## _2 [a] = A ## _2 [b] ; A ## _2 [b] = t2 ; \
39 }
40 
41 #define GB_partition GB_partition_3
42 #define GB_quicksort GB_quicksort_3
43 
44 #include "GB_qsort_template.c"
45 
46 GB_PUBLIC   // accessed by the MATLAB tests in GraphBLAS/Test only
GB_qsort_3(int64_t * restrict A_0,int64_t * restrict A_1,int64_t * restrict A_2,const int64_t n)47 void GB_qsort_3     // sort array A of size 3-by-n, using 3 keys (A [0:2][])
48 (
49     int64_t *restrict A_0,      // size n array
50     int64_t *restrict A_1,      // size n array
51     int64_t *restrict A_2,      // size n array
52     const int64_t n
53 )
54 {
55     uint64_t seed = n ;
56     GB_quicksort (GB_arg (A), n, &seed) ;
57 }
58 
59