mirror of
https://github.com/hanzoai/sql-vector.git
synced 2026-10-01 00:37:19 +00:00
Hardened size macros
(cherry picked from commit 5c97c034a60193dffb50c0de38589e64e8c0c061)
This commit is contained in:
+1
-1
@@ -52,7 +52,7 @@
|
||||
|
||||
#define HALFVEC_MAX_DIM 16000
|
||||
|
||||
#define HALFVEC_SIZE(_dim) (offsetof(HalfVector, x) + sizeof(half)*(_dim))
|
||||
#define HALFVEC_SIZE(_dim) add_size(offsetof(HalfVector, x), mul_size(sizeof(half), _dim))
|
||||
#define DatumGetHalfVector(x) ((HalfVector *) PG_DETOAST_DATUM(x))
|
||||
#define PG_GETARG_HALFVEC_P(x) DatumGetHalfVector(PG_GETARG_DATUM(x))
|
||||
#define PG_RETURN_HALFVEC_P(x) PG_RETURN_POINTER(x)
|
||||
|
||||
+3
-3
@@ -70,10 +70,10 @@ typedef Pointer Item;
|
||||
#define HNSW_MAX_SIZE (BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - MAXALIGN(sizeof(HnswPageOpaqueData)) - sizeof(ItemIdData))
|
||||
#define HNSW_TUPLE_ALLOC_SIZE BLCKSZ
|
||||
|
||||
#define HNSW_ELEMENT_TUPLE_SIZE(size) MAXALIGN(offsetof(HnswElementTupleData, data) + (size))
|
||||
#define HNSW_NEIGHBOR_TUPLE_SIZE(level, m) MAXALIGN(offsetof(HnswNeighborTupleData, indextids) + ((level) + 2) * (m) * sizeof(ItemPointerData))
|
||||
#define HNSW_ELEMENT_TUPLE_SIZE(size) MAXALIGN(add_size(offsetof(HnswElementTupleData, data), size))
|
||||
#define HNSW_NEIGHBOR_TUPLE_SIZE(level, m) MAXALIGN(add_size(offsetof(HnswNeighborTupleData, indextids), mul_size(sizeof(ItemPointerData), mul_size(add_size(level, 2), m))))
|
||||
|
||||
#define HNSW_NEIGHBOR_ARRAY_SIZE(lm) (offsetof(HnswNeighborArray, items) + sizeof(HnswCandidate) * (lm))
|
||||
#define HNSW_NEIGHBOR_ARRAY_SIZE(lm) add_size(offsetof(HnswNeighborArray, items), mul_size(sizeof(HnswCandidate), lm))
|
||||
|
||||
#define HnswPageGetOpaque(page) ((HnswPageOpaque) PageGetSpecialPointer(page))
|
||||
#define HnswPageGetMeta(page) ((HnswMetaPageData *) PageGetContents(page))
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ typedef Pointer Item;
|
||||
#define PROGRESS_IVFFLAT_PHASE_ASSIGN 3
|
||||
#define PROGRESS_IVFFLAT_PHASE_LOAD 4
|
||||
|
||||
#define IVFFLAT_LIST_SIZE(size) (offsetof(IvfflatListData, center) + size)
|
||||
#define IVFFLAT_LIST_SIZE(size) add_size(offsetof(IvfflatListData, center), size)
|
||||
|
||||
#define IvfflatPageGetOpaque(page) ((IvfflatPageOpaque) PageGetSpecialPointer(page))
|
||||
#define IvfflatPageGetMeta(page) ((IvfflatMetaPageData *) PageGetContents(page))
|
||||
|
||||
+5
-1
@@ -26,7 +26,11 @@ typedef struct SparseVector
|
||||
static inline Size
|
||||
SPARSEVEC_SIZE(int nnz)
|
||||
{
|
||||
return offsetof(SparseVector, indices) + (nnz * sizeof(int32)) + (nnz * sizeof(float));
|
||||
Size size = offsetof(SparseVector, indices);
|
||||
|
||||
size = add_size(size, mul_size(sizeof(int32), nnz));
|
||||
size = add_size(size, mul_size(sizeof(float), nnz));
|
||||
return size;
|
||||
}
|
||||
|
||||
static inline float *
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
|
||||
#define VECTOR_MAX_DIM 16000
|
||||
|
||||
#define VECTOR_SIZE(_dim) (offsetof(Vector, x) + sizeof(float)*(_dim))
|
||||
#define VECTOR_SIZE(_dim) add_size(offsetof(Vector, x), mul_size(sizeof(float), _dim))
|
||||
#define DatumGetVector(x) ((Vector *) PG_DETOAST_DATUM(x))
|
||||
#define PG_GETARG_VECTOR_P(x) DatumGetVector(PG_GETARG_DATUM(x))
|
||||
#define PG_RETURN_VECTOR_P(x) PG_RETURN_POINTER(x)
|
||||
|
||||
Reference in New Issue
Block a user