From 97f379931217d2a0a06e588eca54fbe3cf212774 Mon Sep 17 00:00:00 2001 From: Varik Matevosyan Date: Mon, 2 Oct 2023 00:38:44 +0400 Subject: [PATCH 1/2] Fix int overflow issue for progress --- src/hnsw/external_index.c | 14 +++++++------- src/hnsw/external_index.h | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/hnsw/external_index.c b/src/hnsw/external_index.c index e7868e76d..7374b887c 100644 --- a/src/hnsw/external_index.c +++ b/src/hnsw/external_index.c @@ -32,7 +32,7 @@ static uint32 UsearchNodeBytes(usearch_metadata_t *metadata, int vector_bytes, i } static char *extract_node(char *data, - int progress, + progress_t progress, int dim, usearch_metadata_t *metadata, /*->>output*/ int *node_size, @@ -107,7 +107,7 @@ void StoreExternalIndexBlockMapGroup(Relation index, HnswIndexHeaderPage *headerp, ForkNumber forkNum, char *data, - int *progress, + progress_t *progress, int dimension, int first_node_index, size_t num_added_vectors, @@ -275,11 +275,11 @@ void StoreExternalIndex(Relation index, memcpy(headerp->usearch_header, data, USEARCH_HEADER_SIZE); ((PageHeader)header_page)->pd_lower = ((char *)headerp + sizeof(HnswIndexHeaderPage)) - (char *)header_page; - int progress = USEARCH_HEADER_SIZE; // usearch header size - int blockmap_groupno = 0; - int group_node_first_index = 0; - int num_added_vectors_remaining = (int)num_added_vectors; - int batch_size = HNSW_BLOCKMAP_BLOCKS_PER_PAGE; + progress_t progress = USEARCH_HEADER_SIZE; // usearch header size + int blockmap_groupno = 0; + int group_node_first_index = 0; + int num_added_vectors_remaining = (int)num_added_vectors; + int batch_size = HNSW_BLOCKMAP_BLOCKS_PER_PAGE; while(num_added_vectors_remaining > 0) { StoreExternalIndexBlockMapGroup(index, external_index, diff --git a/src/hnsw/external_index.h b/src/hnsw/external_index.h index d2dba03ec..c28419144 100644 --- a/src/hnsw/external_index.h +++ b/src/hnsw/external_index.h @@ -33,6 +33,7 @@ #define USEARCH_HEADER_SIZE 80 +typedef unsigned long long int progress_t; typedef struct HnswIndexHeaderPage { uint32 magicNumber; From 545c4ae028b3b9e15f37a30c3abe379cb84f0ed7 Mon Sep 17 00:00:00 2001 From: Varik Matevosyan Date: Mon, 2 Oct 2023 01:15:38 +0400 Subject: [PATCH 2/2] Change long long to uint64 --- src/hnsw/external_index.c | 14 +++++++------- src/hnsw/external_index.h | 1 - 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/hnsw/external_index.c b/src/hnsw/external_index.c index 7374b887c..1ad8d700a 100644 --- a/src/hnsw/external_index.c +++ b/src/hnsw/external_index.c @@ -32,7 +32,7 @@ static uint32 UsearchNodeBytes(usearch_metadata_t *metadata, int vector_bytes, i } static char *extract_node(char *data, - progress_t progress, + uint64 progress, int dim, usearch_metadata_t *metadata, /*->>output*/ int *node_size, @@ -107,7 +107,7 @@ void StoreExternalIndexBlockMapGroup(Relation index, HnswIndexHeaderPage *headerp, ForkNumber forkNum, char *data, - progress_t *progress, + uint64 *progress, int dimension, int first_node_index, size_t num_added_vectors, @@ -275,11 +275,11 @@ void StoreExternalIndex(Relation index, memcpy(headerp->usearch_header, data, USEARCH_HEADER_SIZE); ((PageHeader)header_page)->pd_lower = ((char *)headerp + sizeof(HnswIndexHeaderPage)) - (char *)header_page; - progress_t progress = USEARCH_HEADER_SIZE; // usearch header size - int blockmap_groupno = 0; - int group_node_first_index = 0; - int num_added_vectors_remaining = (int)num_added_vectors; - int batch_size = HNSW_BLOCKMAP_BLOCKS_PER_PAGE; + uint64 progress = USEARCH_HEADER_SIZE; // usearch header size + int blockmap_groupno = 0; + int group_node_first_index = 0; + int num_added_vectors_remaining = (int)num_added_vectors; + int batch_size = HNSW_BLOCKMAP_BLOCKS_PER_PAGE; while(num_added_vectors_remaining > 0) { StoreExternalIndexBlockMapGroup(index, external_index, diff --git a/src/hnsw/external_index.h b/src/hnsw/external_index.h index c28419144..d2dba03ec 100644 --- a/src/hnsw/external_index.h +++ b/src/hnsw/external_index.h @@ -33,7 +33,6 @@ #define USEARCH_HEADER_SIZE 80 -typedef unsigned long long int progress_t; typedef struct HnswIndexHeaderPage { uint32 magicNumber;