MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / GB_ix_realloc

Function GB_ix_realloc

deps/GraphBLAS/Source/GB_ix_realloc.c:16–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14#include "GB.h"
15
16GB_PUBLIC
17GrB_Info GB_ix_realloc // reallocate space in a matrix
18(
19 GrB_Matrix A, // matrix to allocate space for
20 const int64_t nzmax_new, // new number of entries the matrix can hold
21 GB_Context Context
22)
23{
24
25 //--------------------------------------------------------------------------
26 // check inputs
27 //--------------------------------------------------------------------------
28
29 // This method is used only by GB_ix_resize, which itself is used only by
30 // GB_wait. Full and bitmap matrices never have pending work, so
31 // this function is only called for hypersparse and sparse matrices.
32 ASSERT (!GB_IS_FULL (A)) ;
33 ASSERT (!GB_IS_BITMAP (A)) ;
34 ASSERT (GB_IS_SPARSE (A) || GB_IS_HYPERSPARSE (A)) ;
35
36 // A->p has been allocated but might not be initialized. GB_matvec_check
37 // fails in this case. Thus, ASSERT_MATRIX_OK (A, "A", ...) ; cannot be
38 // used here.
39 ASSERT (A != NULL && A->p != NULL) ;
40 ASSERT (!A->i_shallow && !A->x_shallow) ;
41
42 // This function tolerates pending tuples, zombies, and jumbled matrices.
43 ASSERT (GB_ZOMBIES_OK (A)) ;
44 ASSERT (GB_JUMBLED_OK (A)) ;
45 ASSERT (GB_PENDING_OK (A)) ;
46
47 if (nzmax_new > GB_NMAX)
48 {
49 // problem too large
50 return (GrB_OUT_OF_MEMORY) ;
51 }
52
53 //--------------------------------------------------------------------------
54 // reallocate the space
55 //--------------------------------------------------------------------------
56
57 size_t nzmax_new1 = GB_IMAX (nzmax_new, 1) ;
58 bool ok1 = true, ok2 = true ;
59 GB_REALLOC (A->i, nzmax_new1, int64_t, &(A->i_size), &ok1, Context) ;
60 size_t asize = A->type->size ;
61 if (A->iso)
62 {
63 // shrink A->x so it holds a single entry
64 GB_REALLOC (A->x, asize, GB_void, &(A->x_size), &ok2, Context) ;
65 }
66 else
67 {
68 // reallocate A->x from its current size to nzmax_new1 entries
69 GB_REALLOC (A->x, nzmax_new1*asize, GB_void, &(A->x_size), &ok2,
70 Context) ;
71 }
72 bool ok = ok1 && ok2 ;
73

Callers 3

GrB_InfoFunction · 0.85
mexFunctionFunction · 0.85
mexFunctionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected