| 439 | //------------------------------------------------------------------------------ |
| 440 | |
| 441 | Graph *Graph_New |
| 442 | ( |
| 443 | size_t node_cap, |
| 444 | size_t edge_cap |
| 445 | ) { |
| 446 | |
| 447 | fpDestructor cb = (fpDestructor)AttributeSet_Free; |
| 448 | Graph *g = rm_calloc(1, sizeof(Graph)); |
| 449 | |
| 450 | g->nodes = DataBlock_New(node_cap, node_cap, sizeof(AttributeSet), cb); |
| 451 | g->edges = DataBlock_New(edge_cap, edge_cap, sizeof(AttributeSet), cb); |
| 452 | g->labels = array_new(RG_Matrix, GRAPH_DEFAULT_LABEL_CAP); |
| 453 | g->relations = array_new(RG_Matrix, GRAPH_DEFAULT_RELATION_TYPE_CAP); |
| 454 | |
| 455 | GrB_Info info; |
| 456 | UNUSED(info); |
| 457 | |
| 458 | GrB_Index n = Graph_RequiredMatrixDim(g); |
| 459 | RG_Matrix_new(&g->node_labels, GrB_BOOL, n, n); |
| 460 | RG_Matrix_new(&g->adjacency_matrix, GrB_BOOL, n, n); |
| 461 | RG_Matrix_new(&g->adjacency_matrix->transposed, GrB_BOOL, n, n); |
| 462 | RG_Matrix_new(&g->_zero_matrix, GrB_BOOL, n, n); |
| 463 | |
| 464 | // init graph statistics |
| 465 | GraphStatistics_init(&g->stats); |
| 466 | |
| 467 | // initialize a read-write lock scoped to the individual graph |
| 468 | _CreateRWLock(g); |
| 469 | g->_writelocked = false; |
| 470 | |
| 471 | // force GraphBLAS updates and resize matrices to node count by default |
| 472 | g->SynchronizeMatrix = _MatrixSynchronize; |
| 473 | |
| 474 | return g; |
| 475 | } |
| 476 | |
| 477 | // All graph matrices are required to be squared NXN |
| 478 | // where N = Graph_RequiredMatrixDim. |