File: GB_serialize_method.c

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, 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 (67 lines) | stat: -rw-r--r-- 2,377 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
63
64
65
66
67
//------------------------------------------------------------------------------
// GB_serialize_method: parse the compression method
//------------------------------------------------------------------------------

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

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

#include "GB.h"
#include "serialize/GB_serialize.h"

void GB_serialize_method
(
    // output
    int32_t *algo,                  // algorithm to use
    int32_t *level,                 // compression level
    // input
    int32_t method
)
{

    if (method < 0)
    { 
        // no compression if method is negative
        (*algo) = GxB_COMPRESSION_NONE ;
        (*level) = 0 ;
        return ;
    }

    // Determine the algorithm and level.  Lower levels give faster compression
    // time but not as good of compression.  Higher levels give more compact
    // compressions, at the cost of higher run times.  For all methods: a level
    // of zero, or a level setting outside the range permitted for a method,
    // means that default level for that method is used.
    (*algo) = 1000 * (method / 1000) ;
    (*level) = method % 1000 ;

    switch (*algo)
    {

        default : 
            // The default method has changed to ZSTD, level 1, as of
            // SuiteSparse:GraphBLAS v7.2.0.
            (*algo) = GxB_COMPRESSION_ZSTD ; 
            (*level) = 1 ;              // fast with good compression
            break ;

        case GxB_COMPRESSION_LZ4 : 
            (*level) = 0 ;              // level is ignored
            break ;

        case GxB_COMPRESSION_LZ4HC :    // LZ4HC: level 1 to 9; default 9.
            // Note that LZ4HC supports levels 10, 11, and 12, but these are
            // very slow and do not provide much benefit over level 9.  Level
            // 10 often results in a larger blob than level 9.  Level 12 is
            // typically just a tiny bit more compact than level 9, but can be
            // 10x slower, or worse, as compared to level 9.
            if ((*level) <= 0 || (*level) > 9) (*level) = 9 ;
            break ;

        case GxB_COMPRESSION_ZSTD :     // ZSTD: level 1 to 19; default 1.
            if ((*level) <= 0 || (*level) > 19) (*level) = 1 ;
            break ;
    }
}