1 //------------------------------------------------------------------------------
2 // GxB_Monoid_terminal: return the terminal of a monoid (if any)
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.h"
11 
GxB_Monoid_terminal(bool * has_terminal,void * terminal,GrB_Monoid monoid)12 GrB_Info GxB_Monoid_terminal        // return the monoid terminal
13 (
14     bool *has_terminal,             // true if the monoid has a terminal value
15     void *terminal,                 // returns the terminal of the monoid,
16                                     // unmodified if has_terminal is false
17     GrB_Monoid monoid               // monoid to query
18 )
19 {
20 
21     //--------------------------------------------------------------------------
22     // check inputs
23     //--------------------------------------------------------------------------
24 
25     GB_WHERE1 ("GxB_Monoid_terminal (&has_terminal, &terminal, monoid)") ;
26     GB_RETURN_IF_NULL (has_terminal) ;
27     GB_RETURN_IF_NULL (terminal) ;
28     GB_RETURN_IF_NULL_OR_FAULTY (monoid) ;
29     ASSERT_MONOID_OK (monoid, "monoid for terminal", GB0) ;
30 
31     //--------------------------------------------------------------------------
32     // return the terminal
33     //--------------------------------------------------------------------------
34 
35     (*has_terminal) = (monoid->terminal != NULL) ;
36     if (*has_terminal)
37     {
38         memcpy (terminal, monoid->terminal, monoid->op->ztype->size) ;
39     }
40     return (GrB_SUCCESS) ;
41 }
42 
43