From bb92345683929d2331c76d6e2dba64e774c81881 Mon Sep 17 00:00:00 2001 From: Chen Lixiang Date: Thu, 29 Jun 2023 17:03:35 +0800 Subject: [PATCH] init hnswlab --- .gitignore | 3 +++ CMakeLists.txt | 18 ++++++++++++++++++ README.md | 1 + dataset/.gitkeep | 0 inc/hnsw.h | 29 +++++++++++++++++++++++++++++ inc/utils.h | 6 ++++++ src/hnsw.c | 2 ++ src/test.c | 8 ++++++++ src/utils.c | 0 9 files changed, 67 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 dataset/.gitkeep create mode 100644 inc/hnsw.h create mode 100644 inc/utils.h create mode 100644 src/hnsw.c create mode 100644 src/test.c create mode 100644 src/utils.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e45a29a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/ +*.out +*.exe \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a2da730 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,18 @@ +set(CMAKE_DEBUG_POSTFIX "_d") +set(CMAKE_RELEASE_POSTFIX "_r") +set_target_properties(${TARGET_NAME} PROPERTIES DEBUG_POSTFIX "_d") +set_target_properties(${TARGET_NAME} PROPERTIES RELEASE_POSTFIX "_r") +cmake_minimum_required(VERSION 3.1) +project("hnswlab") +set(CMAKE_C_STANDARD 11) + +# generate .so file +include_directories(inc) +add_library(hnswc +SHARED + src/utils.c + src/hnsw.c +) + +add_executable(hnsw_test src/test.c) +target_link_libraries(hnsw_test hnswc) diff --git a/README.md b/README.md new file mode 100644 index 0000000..a14e22e --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# HNSW-Lab diff --git a/dataset/.gitkeep b/dataset/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/inc/hnsw.h b/inc/hnsw.h new file mode 100644 index 0000000..43a0439 --- /dev/null +++ b/inc/hnsw.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include "utils.h" + +typedef struct NSWGraph +{ + +} NSWGraph; + +typedef struct HNSWGraph +{ + size_t layers_num; // number of layers + NSWGraph **layers; +} HNSWGraph; + +typedef struct HNSWContext +{ + size_t dim; // dimension of dataset + size_t len; // size of dataset + HNSWGraph *graph; // graph of HNSW +} HNSWContext; + +// help functions + +// public functions +HNSWContext *init_hnsw_context(const char *file_path, size_t dim, size_t len); +void insert_vec(HNSWContext *ctx, VecData vec); +void approximate_knn(HNSWContext *ctx, VecData *results); diff --git a/inc/utils.h b/inc/utils.h new file mode 100644 index 0000000..090093e --- /dev/null +++ b/inc/utils.h @@ -0,0 +1,6 @@ + +typedef char* VecData; + +float vec_dist(VecData x, VecData y); + + diff --git a/src/hnsw.c b/src/hnsw.c new file mode 100644 index 0000000..5fe4992 --- /dev/null +++ b/src/hnsw.c @@ -0,0 +1,2 @@ +#include "hnsw.h" + diff --git a/src/test.c b/src/test.c new file mode 100644 index 0000000..4721e0e --- /dev/null +++ b/src/test.c @@ -0,0 +1,8 @@ +#include +#include "hnsw.h" +#include "utils.h" + +int main() { + printf("Hello, world!\n"); + return 0; +} \ No newline at end of file diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..e69de29