Browse Source

init hnswlab

master
Chen Lixiang 1 year ago
commit
bb92345683
9 changed files with 67 additions and 0 deletions
  1. +3
    -0
      .gitignore
  2. +18
    -0
      CMakeLists.txt
  3. +1
    -0
      README.md
  4. +0
    -0
      dataset/.gitkeep
  5. +29
    -0
      inc/hnsw.h
  6. +6
    -0
      inc/utils.h
  7. +2
    -0
      src/hnsw.c
  8. +8
    -0
      src/test.c
  9. +0
    -0
      src/utils.c

+ 3
- 0
.gitignore View File

@ -0,0 +1,3 @@
build/
*.out
*.exe

+ 18
- 0
CMakeLists.txt View File

@ -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)

+ 1
- 0
README.md View File

@ -0,0 +1 @@
# HNSW-Lab

+ 0
- 0
dataset/.gitkeep View File


+ 29
- 0
inc/hnsw.h View File

@ -0,0 +1,29 @@
#pragma once
#include <stdio.h>
#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);

+ 6
- 0
inc/utils.h View File

@ -0,0 +1,6 @@
typedef char* VecData;
float vec_dist(VecData x, VecData y);

+ 2
- 0
src/hnsw.c View File

@ -0,0 +1,2 @@
#include "hnsw.h"

+ 8
- 0
src/test.c View File

@ -0,0 +1,8 @@
#include <stdio.h>
#include "hnsw.h"
#include "utils.h"
int main() {
printf("Hello, world!\n");
return 0;
}

+ 0
- 0
src/utils.c View File


Loading…
Cancel
Save