From 72b74fd01734d5f87635f68dcb0fc215072cf910 Mon Sep 17 00:00:00 2001 From: Chen Lixiang Date: Fri, 30 Jun 2023 12:26:03 +0800 Subject: [PATCH] fix format --- README.md | 4 +++- inc/hnsw.h | 1 - inc/utils.h | 20 +++++++++++--------- src/test.c | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 09d7e3f..d1f1893 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,6 @@ Benchmark started...... Recall value: 1.0000 ``` - ## 2. 开发任务 主要任务为基于 HNSW 算法实现 `src/hnsw.h` 和 `src/hnsw.c` 中的两个函数: @@ -71,6 +70,9 @@ void hnsw_approximate_knn(HNSWContext *ctx, VecData *q, int *results, int k); // 我们已经在 `hnsw_init_context` 中实现了源数据的导入,另外在 `hnsw_approximate_knn` 中实现了一个简单的 KNN 算法以供参考。目前的实现仅能通过 SIFT SMALL 数据集的测试。 +由于 HNSW 的实现需要例如优先队列、集合这样的数据结构辅助,你也可以引入 C++ STL 以提高你的编码效率。 + + ## 3. 数据集下载 SIFT 数据集可以在以下网站中下载: http://corpus-texmex.irisa.fr/ diff --git a/inc/hnsw.h b/inc/hnsw.h index 2a747e6..367fb51 100644 --- a/inc/hnsw.h +++ b/inc/hnsw.h @@ -20,7 +20,6 @@ typedef struct HNSWContext // you can declare some help functions here, and implement them in 'hnsw.c' - // public functions here // Please do not modify these function signatures! // To simply our program, we do not consider reclaiming memory space here. diff --git a/inc/utils.h b/inc/utils.h index 78dcc11..86ce37c 100644 --- a/inc/utils.h +++ b/inc/utils.h @@ -4,20 +4,22 @@ #define GLOBAL_DIM 128 -typedef struct { +typedef struct +{ int id; - float* vec; + float *vec; } VecData; -typedef struct { - FILE* stream; +typedef struct +{ + FILE *stream; char *filename; int offset; } FileContext; float vec_dist(VecData x, VecData y); -FileContext* init_file_context(const char *filename); -void read_4bytes(FileContext* ctx, void* dst); -void read_vec_data(FileContext* ctx, void* dst); -void read_id_data(FileContext* ctx, void* dst, size_t n); -void free_file_context(FileContext* ctx); +FileContext *init_file_context(const char *filename); +void read_4bytes(FileContext *ctx, void *dst); +void read_vec_data(FileContext *ctx, void *dst); +void read_id_data(FileContext *ctx, void *dst, size_t n); +void free_file_context(FileContext *ctx); diff --git a/src/test.c b/src/test.c index ef28565..a454bc7 100644 --- a/src/test.c +++ b/src/test.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) HNSWContext *ctx = hnsw_init_context(argv[1], GLOBAL_DIM, data_size); end = clock(); printf("HNSW Context Initialied OK!\n"); - printf("HNSW initialization cost: %.4f seconds\n", ((float) (end - start)) / CLOCKS_PER_SEC); + printf("HNSW initialization cost: %.4f seconds\n", ((float)(end - start)) / CLOCKS_PER_SEC); VecData q_vec; q_vec.vec = (float *)malloc(sizeof(float) * GLOBAL_DIM); int q_results[K]; @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) start = clock(); hnsw_approximate_knn(ctx, &q_vec, q_results, K); end = clock(); - query_cost += ((float) (end - start)) / CLOCKS_PER_SEC; + query_cost += ((float)(end - start)) / CLOCKS_PER_SEC; total_recall_values += cal_recall_value(q_results, true_results, K); }