File: GB_all_aliased.c

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (62 lines) | stat: -rw-r--r-- 2,185 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//------------------------------------------------------------------------------
// GB_all_aliased: determine if two matrices are entirely aliased
//------------------------------------------------------------------------------

// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//------------------------------------------------------------------------------

// Returns true if A and B are the same or have the same content.  True if A ==
// B (or both NULL), or if all components A and B are aliased to each other.
// In the latter case, that component of A and B will always be shallow, in
// either A or B, or both.  NULL pointers are considered aliased.  The A->Y and
// B->Y hyper_hash matrices are ignored.

#include "GB.h"

// true if pointers p1 and p2 are aliased, or both NULL
#define GB_POINTER_ALIASED(p1,p2) ((p1) == (p2))

bool GB_all_aliased         // determine if A and B are all aliased
(
    GrB_Matrix A,           // input A matrix
    GrB_Matrix B            // input B matrix
)
{

    //--------------------------------------------------------------------------
    // check the matrices themselves
    //--------------------------------------------------------------------------

    if (A == B)
    { 
        // two NULL matrices are equivalent
        return (true) ;
    }

    if (A == NULL || B == NULL)
    { 
        // one of A and B are non-NULL but one of them is NULL, so they are
        // not equal
        return (false) ;
    }

    //--------------------------------------------------------------------------
    // check their content
    //--------------------------------------------------------------------------

    bool all_aliased = 
        GB_POINTER_ALIASED (A->h, B->h) &&
        GB_POINTER_ALIASED (A->p, B->p) &&
        GB_POINTER_ALIASED (A->b, B->b) &&
        GB_POINTER_ALIASED (A->i, B->i) &&
        GB_POINTER_ALIASED (A->x, B->x) ;

    //--------------------------------------------------------------------------
    // return result
    //--------------------------------------------------------------------------

    return (all_aliased) ;
}