From c6491196970eb0db837e5a061cbf84c54c4f3539 Mon Sep 17 00:00:00 2001 From: kaa Date: Wed, 18 Jun 2025 03:39:50 -0700 Subject: 2024/10 hashmap preparation --- graph.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'graph.h') diff --git a/graph.h b/graph.h index 0b6c5c2..6a748ae 100644 --- a/graph.h +++ b/graph.h @@ -15,7 +15,7 @@ typedef struct { } Coordinates; bool -valid(Graph2D* g, Coordinates c) +graph_valid(Graph2D* g, Coordinates c) { return c.x >= 0 && c.x < g->width && c.y >= 0 && c.y < g->height; } @@ -23,7 +23,7 @@ valid(Graph2D* g, Coordinates c) /* Reads from the input until exhausted. Returns memory which must be freed by the caller. */ Graph2D* -ingest(FILE* in) +graph_ingest(FILE* in) { char *t = getall(in); char *s = t; @@ -71,3 +71,15 @@ ingest(FILE* in) free(t); return g; } + +void +graph_free(Graph2D* g) +{ + for (int i = 0; i < g->height; i++) { + free(g->e[i]); + free(g->visited[i]); + } + free(g->e); + free(g->visited); + free(g); +} -- cgit v1.2.3