1 //------------------------------------------------------------------------------
2 // GB_code_size: given a type code, return sizeof (type)
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 // The user-defined type has no known size, so this must be provided on input.
11 
12 #include "GB.h"
13 
14 GB_PUBLIC   // accessed by the MATLAB tests in GraphBLAS/Test only
GB_code_size(const GB_Type_code code,const size_t usize)15 size_t GB_code_size             // return the size of a type, given its code
16 (
17     const GB_Type_code code,    // input code of the type to find the size of
18     const size_t usize          // known size of user-defined type
19 )
20 {
21 
22     switch (code)
23     {
24         case GB_BOOL_code   : return (sizeof (bool))     ;
25         case GB_INT8_code   : return (sizeof (int8_t))   ;
26         case GB_UINT8_code  : return (sizeof (uint8_t))  ;
27         case GB_INT16_code  : return (sizeof (int16_t))  ;
28         case GB_UINT16_code : return (sizeof (uint16_t)) ;
29         case GB_INT32_code  : return (sizeof (int32_t))  ;
30         case GB_UINT32_code : return (sizeof (uint32_t)) ;
31         case GB_INT64_code  : return (sizeof (int64_t))  ;
32         case GB_UINT64_code : return (sizeof (uint64_t)) ;
33         case GB_FP32_code   : return (sizeof (float))    ;
34         case GB_FP64_code   : return (sizeof (double))   ;
35         case GB_FC32_code   : return (sizeof (GxB_FC32_t)) ;
36         case GB_FC64_code   : return (sizeof (GxB_FC64_t)) ;
37         case GB_UDT_code    : return (usize) ;
38         default             : return (0) ;
39     }
40 }
41 
42