commit fdf4491339a8d71d8d7666d850483918bb8dc776
Author: olikru <olikru@tkruger.se>
Date: Mon, 8 Jan 2024 15:17:49 +0100
initial
Diffstat:
6 files changed, 94 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,43 @@
+.SUFFIXES: .c .o .so
+CC=clang
+CFLAGS+=-std=c99 -pedantic -Wall -Werror -Wstrict-prototypes
+CFLAGS+=-Wmissing-prototypes -Wmissing-declarations -Wshadow
+CFLAGS+=-Wpointer-arith -Wcast-qual -Wsign-compare
+CFLAGS+=-O2 -g
+CFLAGS+=-fstack-protector-all -Wtype-limits -fno-common
+CFLAGS+=-fno-builtin
+CFLAGS+=-I/usr/local/include
+
+CFLAGS+=-I$(HOME)/.local/include
+LFLAGS+=-L$(HOME)/.local/lib -lstack_u64
+
+INSTALL_PATH=$(HOME)/.local
+BUILD=build
+
+TEST_SOURCE=test_graph.c
+HEADER=graph.h
+OBJS=graph.o
+SHARED=graph.so
+LIBSHARED=libgraph.so
+
+all: build $(OBJS) $(SHARED) test
+
+.c.o:
+ $(CC) $(CFLAGS) -c $< -o $(BUILD)/$@
+
+.o.so:
+ $(CC) -shared -fPIC $(BUILD)/$< -o $(BUILD)/$@ $(LFLAGS)
+
+test: $(TEST_SOURCE)
+ $(CC) $(CFLAGS) -o $(BUILD)/test $(TEST_SOURCE) $(BUILD)/$(OBJS) $(LFLAGS)
+
+build:
+ mkdir -p $(BUILD)
+
+install:
+ cp $(BUILD)/$(SHARED) $(INSTALL_PATH)/lib/$(LIBSHARED)
+ chmod 644 $(INSTALL_PATH)/lib/$(LIBSHARED)
+ cp $(HEADER) $(INSTALL_PATH)/include/
+
+clean:
+ rm -rf $(BUILD)
diff --git a/README b/README
@@ -0,0 +1,4 @@
+graph
+=====
+
+Graph/multigraph type with some related, simple, functions.
diff --git a/TODO b/TODO
@@ -0,0 +1,2 @@
+* Implement unit tests
+* Documentation
diff --git a/graph.c b/graph.c
@@ -0,0 +1,22 @@
+#include "graph.h"
+
+void graph_init(graph_t *g, const size_t n) {
+ g->n = n;
+ g->nbrs = malloc(n * sizeof(*(g->nbrs)));
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ stack_u64_init(&g->nbrs[i]);
+}
+
+void graph_clear(graph_t *g) {
+ size_t i;
+ for (i = 0; i < g->n; i++)
+ stack_u64_clear(&g->nbrs[i]);
+ free(g->nbrs);
+}
+
+void graph_add_edge(graph_t *g, const size_t v, const size_t w) {
+ stack_u64_push(&g->nbrs[v], w);
+ stack_u64_push(&g->nbrs[w], v);
+}
diff --git a/graph.h b/graph.h
@@ -0,0 +1,15 @@
+#ifndef GRAPH_H
+#define GRAPH_H
+
+#include "stack_u64.h"
+
+typedef struct {
+ size_t n;
+ stack_u64_t *nbrs;
+} graph_t;
+
+void graph_init(graph_t *g, const size_t n);
+void graph_clear(graph_t *g);
+void graph_add_edge(graph_t *g, const size_t v, const size_t w);
+
+#endif
diff --git a/test_graph.c b/test_graph.c
@@ -0,0 +1,8 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include "fheap.h"
+
+int main() {
+ printf("test unimplemented\n");
+}