[graph] graph_load and graph_save
This commit is contained in:
26
src/graph.c
26
src/graph.c
@@ -147,6 +147,19 @@ exit_graph_allocated:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
graph_t *graph_load(char *path) {
|
||||||
|
FILE *f;
|
||||||
|
|
||||||
|
if ((f = fopen(path, "rb")) == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
graph_t *graph = graph_read(f);
|
||||||
|
fclose(f);
|
||||||
|
return graph;
|
||||||
|
}
|
||||||
|
|
||||||
bool graph_write(graph_t *self, FILE *f) {
|
bool graph_write(graph_t *self, FILE *f) {
|
||||||
if (self == NULL || self->indptr == NULL || self->indices == NULL) {
|
if (self == NULL || self->indptr == NULL || self->indices == NULL) {
|
||||||
return false;
|
return false;
|
||||||
@@ -184,3 +197,16 @@ bool graph_write(graph_t *self, FILE *f) {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool graph_save(graph_t *self, char *path) {
|
||||||
|
FILE *f;
|
||||||
|
if ((f = fopen(path, "wb")) == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool status = graph_write(self, f);
|
||||||
|
fclose(f);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,9 @@ void graph_append_edges(graph_t *self, uint32_t *col, size_t n);
|
|||||||
void graph_finalize_vertex(graph_t *self);
|
void graph_finalize_vertex(graph_t *self);
|
||||||
|
|
||||||
bool graph_write(graph_t *self, FILE *f);
|
bool graph_write(graph_t *self, FILE *f);
|
||||||
|
bool graph_save(graph_t *self, char *path);
|
||||||
graph_t *graph_read(FILE *f);
|
graph_t *graph_read(FILE *f);
|
||||||
|
graph_t *graph_load(char *path);
|
||||||
|
|
||||||
#define graph_foreach_row(g, row_var, index_var, length_var, code) { \
|
#define graph_foreach_row(g, row_var, index_var, length_var, code) { \
|
||||||
uint32_t _row_start = 0, _row_end = 0; \
|
uint32_t _row_start = 0, _row_end = 0; \
|
||||||
|
|||||||
Reference in New Issue
Block a user