-
Notifications
You must be signed in to change notification settings - Fork 0
/
anyarray.h
100 lines (87 loc) · 2.61 KB
/
anyarray.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*-------------------------------------------------------------------------
*
* anyarray.h
* anyarray common declarations
*
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
*
* Copyright (c) 2023, Postgres Professional
*
* Author: Teodor Sigaev <[email protected]>,
* Oleg Bartunov <[email protected]>
*
* IDENTIFICATION
* contrib/anyarray/anyarray.c
*
*-------------------------------------------------------------------------
*/
#ifndef _ANYARRAY_H_
#define _ANYARRAY_H_
#include "postgres.h"
#include "fmgr.h"
#include "nodes/memnodes.h"
#include "utils/array.h"
typedef struct AnyArrayTypeInfo
{
Oid typid;
int16 typlen;
bool typbyval;
char typalign;
MemoryContext funcCtx;
Oid cmpFuncOid;
bool cmpFuncInited;
FmgrInfo cmpFunc;
bool hashFuncInited;
Oid hashFuncOid;
FmgrInfo hashFunc;
} AnyArrayTypeInfo;
typedef struct SimpleArray
{
Datum *elems;
int32 *hashedElems;
int32 nelems;
int32 nHashedElems;
AnyArrayTypeInfo *info;
} SimpleArray;
#define LINEAR_LIMIT (5)
#define NDIM 1
#define ARRISVOID(x) ((x) == NULL || ARRNELEMS(x) == 0)
#define ARRNELEMS(x) ArrayGetNItems(ARR_NDIM(x), ARR_DIMS(x))
/* reject arrays we can't handle; but allow a NULL or empty array */
#define CHECKARRVALID(x) \
do { \
if (x) { \
if (ARR_NDIM(x) != NDIM && ARR_NDIM(x) != 0) \
ereport(ERROR, \
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), \
errmsg("array must be one-dimensional"))); \
if (ARR_HASNULL(x) && array_contains_nulls(x)) \
ereport(ERROR, \
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), \
errmsg("array must not contain nulls"))); \
} \
} while(0)
typedef enum SimilarityType {
AA_Cosine,
AA_Jaccard,
AA_Overlap
} SimilarityType;
extern SimilarityType SmlType;
extern double SmlLimit;
#define AnyAarraySimilarityStrategy (16)
/*
* Various support functions
*/
extern AnyArrayTypeInfo* getAnyArrayTypeInfo(MemoryContext ctx, Oid typid);
extern void freeAnyArrayTypeInfo(AnyArrayTypeInfo *info);
extern AnyArrayTypeInfo* getAnyArrayTypeInfoCached(FunctionCallInfo fcinfo, Oid typid);
extern void cmpFuncInit(AnyArrayTypeInfo* info);
extern void hashFuncInit(AnyArrayTypeInfo* info);
extern SimpleArray* Array2SimpleArray(AnyArrayTypeInfo *info, ArrayType *a);
extern void freeSimpleArray(SimpleArray* s);
extern ArrayType* SimpleArray2Array(SimpleArray *s);
extern void sortSimpleArray(SimpleArray *s, int32 direction);
extern void uniqSimpleArray(SimpleArray *s, bool onlyDuplicate);
extern void hashSimpleArray(SimpleArray *s);
extern double getSimilarity(SimpleArray *sa, SimpleArray *sb);
#endif