addition: Base for implementation
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -16,6 +16,7 @@ Testing/
|
||||
compile_commands.json
|
||||
../compile_commands.json
|
||||
build/compile_commands.json
|
||||
cmake
|
||||
|
||||
# Make / Ninja
|
||||
Makefile
|
||||
|
||||
@@ -11,6 +11,14 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
option(GRAPH_BUILD_TESTS "Build arraylist tests" OFF)
|
||||
option(GRAPH_ENABLE_SANITIZERS "Enable sanitizers for tests" ON)
|
||||
|
||||
include(cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME arraylist
|
||||
GIT_REPOSITORY https://laentropia-homelab.tail7368da.ts.net/laentropia/ArrayList.git
|
||||
GIT_TAG main
|
||||
)
|
||||
|
||||
# ------------------------
|
||||
# Library
|
||||
# ------------------------
|
||||
@@ -39,6 +47,10 @@ target_link_libraries(graph_example
|
||||
graph
|
||||
)
|
||||
|
||||
target_link_libraries(graph
|
||||
PUBLIC arraylist
|
||||
)
|
||||
|
||||
# ------------------------
|
||||
# Testing
|
||||
# ------------------------
|
||||
|
||||
@@ -1,6 +1,20 @@
|
||||
#ifndef GRAPH_H
|
||||
#define GRAPH_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct Graph Graph;
|
||||
typedef struct Vertex Vertex;
|
||||
typedef struct Edge Edge;
|
||||
|
||||
typedef enum {
|
||||
GRAPH_OK,
|
||||
} GraphErr ;
|
||||
|
||||
typedef enum {
|
||||
GRAPH_DIRECTED,
|
||||
GRAPH_UNDIRECTED,
|
||||
} GraphType;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
21
src/graph.c
21
src/graph.c
@@ -1 +1,22 @@
|
||||
#include "graph.h"
|
||||
#include "arraylist.h"
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct Vertex {
|
||||
void *data;
|
||||
ArrayList *edges;
|
||||
};
|
||||
|
||||
struct Edge {
|
||||
size_t *to;
|
||||
intmax_t weight;
|
||||
};
|
||||
|
||||
struct Graph {
|
||||
ArrayList *vertices;
|
||||
GraphType type;
|
||||
|
||||
int (*cmp)(const void*, const void*);
|
||||
void (*free_data)(void*);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user