Line data Source code
1 : //------------------------------------------------------------------------------ 2 : // LG_qsort_3: sort a 3-by-n list of integers, using A[0:2][] as the key 3 : //------------------------------------------------------------------------------ 4 : 5 : // LAGraph, (c) 2019-2022 by The LAGraph Contributors, All Rights Reserved. 6 : // SPDX-License-Identifier: BSD-2-Clause 7 : // 8 : // For additional details (including references to third party source code and 9 : // other files) see the LICENSE file or contact permission@sei.cmu.edu. See 10 : // Contributors.txt for a full list of contributors. Created, in part, with 11 : // funding and support from the U.S. Government (see Acknowledgments.txt file). 12 : // DM22-0790 13 : 14 : // Contributed by Timothy A. Davis, Texas A&M University 15 : 16 : //------------------------------------------------------------------------------ 17 : 18 : #include "LG_internal.h" 19 : 20 : // returns true if A [a] < B [b] 21 : #define LG_lt(A,a,B,b) \ 22 : LG_lt_3 (A ## _0, A ## _1, A ## _2, a, B ## _0, B ## _1, B ## _2, b) 23 : 24 : // argument list for calling a function 25 : #define LG_arg(A) \ 26 : A ## _0, A ## _1, A ## _2 27 : 28 : // argument list for calling a function, with offset 29 : #define LG_arg_offset(A,x) \ 30 : A ## _0 + (x), A ## _1 + (x), A ## _2 + (x) 31 : 32 : // argument list for defining a function 33 : #define LG_args(A) \ 34 : int64_t *LG_RESTRICT A ## _0, \ 35 : int64_t *LG_RESTRICT A ## _1, \ 36 : int64_t *LG_RESTRICT A ## _2 37 : 38 : // each entry has a 3-integer key 39 : #define LG_K 3 40 : 41 : // swap A [a] and A [b] 42 : #define LG_swap(A,a,b) \ 43 : { \ 44 : int64_t t0 = A ## _0 [a] ; A ## _0 [a] = A ## _0 [b] ; A ## _0 [b] = t0 ; \ 45 : int64_t t1 = A ## _1 [a] ; A ## _1 [a] = A ## _1 [b] ; A ## _1 [b] = t1 ; \ 46 : int64_t t2 = A ## _2 [a] ; A ## _2 [a] = A ## _2 [b] ; A ## _2 [b] = t2 ; \ 47 : } 48 : 49 : #define LG_partition LG_partition_3 50 : #define LG_quicksort LG_quicksort_3 51 : 52 : #include "LG_qsort_template.h" 53 : 54 169 : void LG_qsort_3 // sort array A of size 3-by-n, using 3 keys (A [0:2][]) 55 : ( 56 : int64_t *LG_RESTRICT A_0, // size n array 57 : int64_t *LG_RESTRICT A_1, // size n array 58 : int64_t *LG_RESTRICT A_2, // size n array 59 : const int64_t n 60 : ) 61 : { 62 169 : uint64_t seed = n ; 63 169 : LG_quicksort (LG_arg (A), n, &seed, NULL) ; 64 169 : }