1 /* ========================================================================== */
2 /* === UMF_is_permutation =================================================== */
3 /* ========================================================================== */
4
5 /* -------------------------------------------------------------------------- */
6 /* UMFPACK Copyright (c) Timothy A. Davis, CISE, */
7 /* Univ. of Florida. All Rights Reserved. See ../Doc/License for License. */
8 /* web: http://www.cise.ufl.edu/research/sparse/umfpack */
9 /* -------------------------------------------------------------------------- */
10
11 /* Return TRUE if P is a r-permutation vector, FALSE otherwise */
12 /* P [0..r-1] must be an r-permutation of 0..n-1 */
13
14 #include "umf_internal.h"
15
UMF_is_permutation(const Int P[],Int W[],Int n,Int r)16 GLOBAL Int UMF_is_permutation
17 (
18 const Int P [ ], /* permutation of size r */
19 Int W [ ], /* workspace of size n */
20 Int n,
21 Int r
22 )
23 {
24 Int i, k ;
25
26 if (!P)
27 {
28 /* if P is (Int *) NULL, this is the identity permutation */
29 return (TRUE) ;
30 }
31
32 ASSERT (W != (Int *) NULL) ;
33
34 for (i = 0 ; i < n ; i++)
35 {
36 W [i] = FALSE ;
37 }
38 for (k = 0 ; k < r ; k++)
39 {
40 i = P [k] ;
41 DEBUG5 (("k " ID " i " ID "\n", k, i)) ;
42 if (i < 0 || i >= n)
43 {
44 DEBUG0 (("i out of range " ID " " ID "\n", i, n)) ;
45 return (FALSE) ;
46 }
47 if (W [i])
48 {
49 DEBUG0 (("i duplicate " ID "\n", i)) ;
50 return (FALSE) ;
51 }
52 W [i] = TRUE ;
53 }
54 return (TRUE) ;
55 }
56