#endif
static Oid
-getDefaultOpclass(Oid amoid, Oid typid)
+getDefaultOpclass(Oid amoid, Oid typid)
{
ScanKeyData skey;
SysScanDesc scan;
Relation heapRel;
Oid opclassOid = InvalidOid;
- heapRel = heap_open(OperatorClassRelationId, AccessShareLock);
+ heapRel = heap_open(OperatorClassRelationId, AccessShareLock);
ScanKeyInit(&skey,
Anum_pg_opclass_opcmethod,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(amoid));
- scan = systable_beginscan(heapRel,
- OpclassAmNameNspIndexId, true,
+ scan = systable_beginscan(heapRel,
+ OpclassAmNameNspIndexId, true,
SNAPSHOT, 1, &skey);
while (HeapTupleIsValid((tuple = systable_getnext(scan))))
}
static Oid
-getAMProc(Oid amoid, Oid typid)
+getAMProc(Oid amoid, Oid typid)
{
Oid opclassOid = getDefaultOpclass(amoid, typid);
Oid procOid = InvalidOid;
for (i = 0; i < catlist->n_members; i++)
{
- HeapTuple tuple = &catlist->members[i]->tuple;
+ HeapTuple tuple = &catlist->members[i]->tuple;
Form_pg_cast castForm = (Form_pg_cast)GETSTRUCT(tuple);
if ( castForm->castfunc == InvalidOid && castForm->castcontext == COERCION_CODE_IMPLICIT )
ReleaseSysCacheList(catlist);
}
-
+
if ( !OidIsValid(opclassOid) )
return InvalidOid;
#endif
scan = systable_beginscan(heapRel, AccessMethodProcedureIndexId, true,
- SNAPSHOT,
+ SNAPSHOT,
#if PG_VERSION_NUM >= 90200
4,
#else
info->cmpFuncOid = getAMProc(BTREE_AM_OID, info->tupDesc->attrs[0]->atttypid);
info->hashFuncOid = getAMProc(HASH_AM_OID, info->tupDesc->attrs[0]->atttypid);
- }
- else
+ }
+ else
{
info->tupDesc = NULL;
Assert( av->typid != bv->typid );
- return ( av->typid > bv->typid ) ? 1 : -1;
+ return ( av->typid > bv->typid ) ? 1 : -1;
}
ProcTypeInfo
if ( nCacheProcs == 1 )
{
- if ( cacheProcs[0]->typid == typid )
+ if ( cacheProcs[0]->typid == typid )
{
/*cacheProcs[0]->hashFuncInited = cacheProcs[0]->cmpFuncInited = false;*/
return cacheProcs[0];
else if ( nCacheProcs > 1 )
{
ProcTypeInfo *StopMiddle;
- ProcTypeInfo *StopLow = cacheProcs,
+ ProcTypeInfo *StopLow = cacheProcs,
*StopHigh = cacheProcs + nCacheProcs;
while (StopLow < StopHigh) {
}
info = fillProcs(typid);
- if ( nCacheProcs == 0 )
+ if ( nCacheProcs == 0 )
{
cacheProcs = malloc(sizeof(ProcTypeInfo));
{
ProcTypeInfo info = (ProcTypeInfo)arg;
- if (info->tupDesc)
+ if (info->tupDesc)
/* composite type */
return DatumGetInt32( FCall2( &info->cmpFunc,
- deconstructCompositeType(info, *(Datum*)a, NULL),
- deconstructCompositeType(info, *(Datum*)b, NULL) ) );
+ deconstructCompositeType(info, *(Datum*)a, NULL),
+ deconstructCompositeType(info, *(Datum*)b, NULL) ) );
return DatumGetInt32( FCall2( &info->cmpFunc,
*(Datum*)a, *(Datum*)b ) );
static int
cmpArrayElemArg(const void *a, const void *b, void *arg)
{
- cmpArrayElemData *data = (cmpArrayElemData*)arg;
- int res;
+ cmpArrayElemData *data = (cmpArrayElemData*)arg;
+ int res;
if (data->info->tupDesc)
res = DatumGetInt32( FCall2( &data->info->cmpFunc,
- deconstructCompositeType(data->info, *(Datum*)a, NULL),
- deconstructCompositeType(data->info, *(Datum*)b, NULL) ) );
+ deconstructCompositeType(data->info, *(Datum*)a, NULL),
+ deconstructCompositeType(data->info, *(Datum*)b, NULL) ) );
else
res = DatumGetInt32( FCall2( &data->info->cmpFunc,
*(Datum*)a, *(Datum*)b ) );
if ( s->nelems > 1 )
{
cmpArrayElemData data;
- int i;
+ int i;
getFmgrInfoCmp(s->info);
data.info = s->info;
break;
default:
elog(ERROR,"Unknown TF method: %d", tfm);
- }
+ }
}
else
{
s->df[i] = 0.0; /* unknown word */
}
- }
+ }
}
}
else if ( cache )
}
}
}
- else if (s->nelems > 0 && cache)
+ else if (s->nelems > 0 && cache)
{
stat = fingArrayStat(cache, s->info->typid, s->elems[0], stat);
if ( stat )
{
ArrayType *a, *b;
SimpleArray *sa, *sb;
-
- fcinfo->flinfo->fn_extra = SearchArrayCache(
+
+ fcinfo->flinfo->fn_extra = SearchArrayCache(
fcinfo->flinfo->fn_extra,
fcinfo->flinfo->fn_mcxt,
PG_GETARG_DATUM(0), &a, &sa, NULL);
- fcinfo->flinfo->fn_extra = SearchArrayCache(
+ fcinfo->flinfo->fn_extra = SearchArrayCache(
fcinfo->flinfo->fn_extra,
fcinfo->flinfo->fn_mcxt,
PG_GETARG_DATUM(1), &b, &sb, NULL);
switch(getSmlType())
{
- case ST_TFIDF:
+ case ST_TFIDF:
PG_RETURN_FLOAT4( TFIDFSml(sa, sb) );
break;
- case ST_COSINE:
+ case ST_COSINE:
{
int cnt;
double power;
PG_RETURN_FLOAT4( ((double)cnt) / sqrt( power ) );
}
break;
- case ST_OVERLAP:
+ case ST_OVERLAP:
{
float4 res = (float4)numOfIntersect(sa, sb);
elog(ERROR,"Unsupported formula type of similarity");
}
- PG_RETURN_FLOAT4(0.0); /* keep compiler quiet */
+ PG_RETURN_FLOAT4(0.0); /* keep compiler quiet */
}
PG_FUNCTION_INFO_V1(arraysmlw);
ArrayType *a, *b;
SimpleArray *sa, *sb;
bool useIntersect = PG_GETARG_BOOL(2);
- double numerator = 0.0;
- double denominatorA = 0.0,
+ double numerator = 0.0;
+ double denominatorA = 0.0,
denominatorB = 0.0,
tmpA, tmpB;
int cmp;
ProcTypeInfo info;
int ai = 0, bi = 0;
-
- fcinfo->flinfo->fn_extra = SearchArrayCache(
+ fcinfo->flinfo->fn_extra = SearchArrayCache(
fcinfo->flinfo->fn_extra,
fcinfo->flinfo->fn_mcxt,
PG_GETARG_DATUM(0), &a, &sa, NULL);
- fcinfo->flinfo->fn_extra = SearchArrayCache(
+ fcinfo->flinfo->fn_extra = SearchArrayCache(
fcinfo->flinfo->fn_extra,
fcinfo->flinfo->fn_mcxt,
PG_GETARG_DATUM(1), &b, &sb, NULL);
ArrayType *a, *b;
SimpleArray *sa, *sb;
double power = 0.0;
-
- fcinfo->flinfo->fn_extra = SearchArrayCache(
+
+ fcinfo->flinfo->fn_extra = SearchArrayCache(
fcinfo->flinfo->fn_extra,
fcinfo->flinfo->fn_mcxt,
PG_GETARG_DATUM(0), &a, &sa, NULL);
- fcinfo->flinfo->fn_extra = SearchArrayCache(
+ fcinfo->flinfo->fn_extra = SearchArrayCache(
fcinfo->flinfo->fn_extra,
fcinfo->flinfo->fn_mcxt,
PG_GETARG_DATUM(1), &b, &sb, NULL);
switch(getSmlType())
{
- case ST_TFIDF:
+ case ST_TFIDF:
power = TFIDFSml(sa, sb);
break;
- case ST_COSINE:
+ case ST_COSINE:
{
int cnt;
power = ((double)cnt) / power;
}
break;
- case ST_OVERLAP:
+ case ST_OVERLAP:
power = (double)numOfIntersect(sa, sb);
break;
default:
bool isnull;
void *plan;
int stat;
- text *formula = PG_GETARG_TEXT_P(2);
-
- fcinfo->flinfo->fn_extra = SearchArrayCache(
+ text *formula = PG_GETARG_TEXT_P(2);
+
+ fcinfo->flinfo->fn_extra = SearchArrayCache(
fcinfo->flinfo->fn_extra,
fcinfo->flinfo->fn_mcxt,
PG_GETARG_DATUM(0), &a, &sa, NULL);
- fcinfo->flinfo->fn_extra = SearchArrayCache(
+ fcinfo->flinfo->fn_extra = SearchArrayCache(
fcinfo->flinfo->fn_extra,
fcinfo->flinfo->fn_mcxt,
PG_GETARG_DATUM(1), &b, &sb, NULL);
SPI_connect();
-
if ( cachedPlan == NULL || cachedLen != VARSIZE(formula) - VARHDRSZ ||
memcmp( cachedFormula, VARDATA(formula), VARSIZE(formula) - VARHDRSZ ) != 0 )
{
SPI_freeplan(plan);
cachedLen = VARSIZE(formula) - VARHDRSZ;
- memcpy( cachedFormula, VARDATA(formula), VARSIZE(formula) - VARHDRSZ );
+ memcpy( cachedFormula, VARDATA(formula), VARSIZE(formula) - VARHDRSZ );
}
plan = cachedPlan;
{
ArrayType *a;
SimpleArray *sa;
- Datum query = PG_GETARG_DATUM(1);
+ Datum query = PG_GETARG_DATUM(1);
Oid queryTypeOid;
Datum *StopLow,
*StopHigh,
*StopMiddle;
int cmp;
- fcinfo->flinfo->fn_extra = SearchArrayCache(
+ fcinfo->flinfo->fn_extra = SearchArrayCache(
fcinfo->flinfo->fn_extra,
fcinfo->flinfo->fn_mcxt,
PG_GETARG_DATUM(0), &a, &sa, NULL);
StopLow = sa->elems;
StopHigh = sa->elems + sa->nelems;
- while (StopLow < StopHigh)
+ while (StopLow < StopHigh)
{
StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
cmp = cmpArrayElem(StopMiddle, &query, sa->info);
Datum *elems;
double *df; /* frequency in current doc */
uint32 *hash;
- int nelems;
+ int nelems;
ProcTypeInfo info;
} SimpleArray;
* GiST
*/
-#define SmlarOverlapStrategy 1
-#define SmlarSimilarityStrategy 2
+#define SmlarOverlapStrategy 1
+#define SmlarSimilarityStrategy 2
struct SmlSign;
struct SmlSign* Array2HashedArray(ProcTypeInfo info, ArrayType *a);
/*
* Cache subsystem
*/
-void* SearchArrayCache( void *cache, MemoryContext ctx, Datum a, ArrayType **da, SimpleArray **sa, struct SmlSign **ss );
+void* SearchArrayCache( void *cache, MemoryContext ctx, Datum a, ArrayType **da, SimpleArray **sa, struct SmlSign **ss );
typedef struct StatElem {
- Datum datum;
- double idf; /* log(d/df) */
+ Datum datum;
+ double idf; /* log(d/df) */
} StatElem;
typedef struct HashedElem {
} SignedElem;
typedef struct StatCache {
- StatElem *elems;
- int nelems;
- int64_t ndoc;
+ StatElem *elems;
+ int nelems;
+ int64_t ndoc;
HashedElem *helems;
- int nhelems;
+ int nhelems;
SignedElem *selems;
- ProcTypeInfo info;
+ ProcTypeInfo info;
} StatCache;
StatCache *initStatCache(MemoryContext ctx);
StatCache *DocStat;
} ArrayCache;
-static void
+static void
moveFirst(ArrayCache *ac, ArrayCacheEntry *entry)
{
/*
}
/*
- * Install into head
+ * Install into head
*/
Assert( ac->head != NULL );
ac->head = entry;
}
-#define DATUMSIZE(d) VARSIZE_ANY(DatumGetPointer(d))
+#define DATUMSIZE(d) VARSIZE_ANY(DatumGetPointer(d))
static int
cmpDatum(Datum a, Datum b)
{
ac->ctx = ctx;
/*
- * Fast check of resent used value
+ * Fast check of resent used value
*/
if ( ac->head && cmpDatum(ac->head->toastedArray, a) == 0 )
{
ArrayCacheEntry **StopMiddle;
int cmp;
- while (StopLow < StopHigh) {
+ while (StopLow < StopHigh) {
StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
entry = *StopMiddle;
- cmp = cmpDatum(entry->toastedArray, a);
+ cmp = cmpDatum(entry->toastedArray, a);
if ( cmp == 0 )
{
} while(0);
/*
- * Not found
+ * Not found
*/
if ( ac->nentries < NENTRIES )
makeEntry(ac, ac->head, a);
fetchData(ac, ac->head, da, sa, ss);
- }
+ }
else
{
cleanupData( ac->tail );
fetchData(ac, ac->head, da, sa, ss);
}
- qsort(ac->entries, ac->nentries, sizeof(ArrayCacheEntry*), cmpEntry);
+ qsort(ac->entries, ac->nentries, sizeof(ArrayCacheEntry*), cmpEntry);
return cache;
}
if ( typoid != ac->DocStat->info->typid )
elog(ERROR,"Types of stat table and actual arguments are different");
- return findStat(ac->DocStat, query, low);
+ return findStat(ac->DocStat, query, low);
}
StatCache *
getStat(void *cache, size_t n)
{
- ArrayCache *ac;
+ ArrayCache *ac;
if ( cache == NULL )
return NULL;
smlararrayextract(PG_FUNCTION_ARGS)
{
ArrayType *array;
- int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
+ int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
SimpleArray *sa;
/*
if (sa->nelems == 0 && PG_NARGS() == 3)
{
- switch (PG_GETARG_UINT16(2)) /* StrategyNumber */
+ switch (PG_GETARG_UINT16(2)) /* StrategyNumber */
{
case SmlarOverlapStrategy:
case SmlarSimilarityStrategy:
Datum
smlararrayconsistent(PG_FUNCTION_ARGS)
{
- bool *check = (bool *) PG_GETARG_POINTER(0);
- StrategyNumber strategy = PG_GETARG_UINT16(1);
+ bool *check = (bool *) PG_GETARG_POINTER(0);
+ StrategyNumber strategy = PG_GETARG_UINT16(1);
SimpleArray *sa;
bool res = false;
int i,
cnt = 0;
- bool *recheck = (bool *) PG_GETARG_POINTER(5);
+ bool *recheck = (bool *) PG_GETARG_POINTER(5);
*recheck = true;
switch(getSmlType())
{
- case ST_TFIDF:
+ case ST_TFIDF:
{
- double weight = 0.0, /* exact weight of union */
+ double weight = 0.0, /* exact weight of union */
saSum = 0.0, /* exact length of query */
siSum = 0.0; /* lower limit of length of indexed value */
res = true;
}
break;
- case ST_COSINE:
+ case ST_COSINE:
{
double power;
res = true;
}
break;
- case ST_OVERLAP:
+ case ST_OVERLAP:
if (cnt >= GetSmlarLimit())
res = true;
break;
#define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
#define HASH(sign, val) SETBIT((sign), HASHVAL(val))
-#define ARRKEY 0x01
-#define SIGNKEY 0x02
-#define ALLISTRUE 0x04
+#define ARRKEY 0x01
+#define SIGNKEY 0x02
+#define ALLISTRUE 0x04
-#define ISARRKEY(x) ( ((SmlSign*)x)->flag & ARRKEY )
-#define ISSIGNKEY(x) ( ((SmlSign*)x)->flag & SIGNKEY )
-#define ISALLTRUE(x) ( ((SmlSign*)x)->flag & ALLISTRUE )
+#define ISARRKEY(x) ( ((SmlSign*)x)->flag & ARRKEY )
+#define ISSIGNKEY(x) ( ((SmlSign*)x)->flag & SIGNKEY )
+#define ISALLTRUE(x) ( ((SmlSign*)x)->flag & ALLISTRUE )
-#define CALCGTSIZE(flag, len) ( SMLSIGNHDRSZ + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(uint32)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) )
-#define GETSIGN(x) ( (BITVECP)( (char*)x+SMLSIGNHDRSZ ) )
-#define GETARR(x) ( (uint32*)( (char*)x+SMLSIGNHDRSZ ) )
+#define CALCGTSIZE(flag, len) ( SMLSIGNHDRSZ + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(uint32)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) )
+#define GETSIGN(x) ( (BITVECP)( (char*)x+SMLSIGNHDRSZ ) )
+#define GETARR(x) ( (uint32*)( (char*)x+SMLSIGNHDRSZ ) )
#define GETENTRY(vec,pos) ((SmlSign *) DatumGetPointer((vec)->vector[(pos)].key))
* Fake IO
*/
PG_FUNCTION_INFO_V1(gsmlsign_in);
-Datum gsmlsign_in(PG_FUNCTION_ARGS);
+Datum gsmlsign_in(PG_FUNCTION_ARGS);
Datum
gsmlsign_in(PG_FUNCTION_ARGS)
{
}
PG_FUNCTION_INFO_V1(gsmlsign_out);
-Datum gsmlsign_out(PG_FUNCTION_ARGS);
+Datum gsmlsign_out(PG_FUNCTION_ARGS);
Datum
gsmlsign_out(PG_FUNCTION_ARGS)
{
/* Number of one-bits in an unsigned byte */
static const uint8 number_of_ones[256] = {
- 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
+ 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
static int
compareint(const void *va, const void *vb)
{
- uint32 a = *((uint32 *) va);
- uint32 b = *((uint32 *) vb);
-
+ uint32 a = *((uint32 *) va);
+ uint32 b = *((uint32 *) vb);
+
if (a == b)
return 0;
return (a > b) ? 1 : -1;
static int
uniqueint(uint32 *a, int32 l, int32 *max)
{
- uint32 *ptr,
- *res;
- int32 cnt = 0;
+ uint32 *ptr,
+ *res;
+ int32 cnt = 0;
*max = 1;
ptr = GETARR(sign);
for(i=0;i<s->nelems;i++)
ptr[i] = DatumGetUInt32( FunctionCall1( &s->info->hashFunc, s->elems[i] ) );
-
+
/*
* there is a collision of hash-function; len is always equal or less than
* s->nelems
static int
HashedElemCmp(const void *va, const void *vb)
{
- uint32 a = ((HashedElem *) va)->hash;
- uint32 b = ((HashedElem *) vb)->hash;
-
+ uint32 a = ((HashedElem *) va)->hash;
+ uint32 b = ((HashedElem *) vb)->hash;
+
if (a == b)
{
double ma = ((HashedElem *) va)->idfMin;
static int
uniqueHashedElem(HashedElem *a, int32 l)
{
- HashedElem *ptr,
- *res;
+ HashedElem *ptr,
+ *res;
if (l <= 1)
return l;
for(i=0;i<stat->nelems;i++)
{
uint32 hash = DatumGetUInt32( FunctionCall1( &stat->info->hashFunc, stat->elems[i].datum ) );
- int index = HASHVAL(hash);
+ int index = HASHVAL(hash);
stat->helems[i].hash = hash;
stat->helems[i].idfMin = stat->helems[i].idfMax = stat->elems[i].idf;
stat->selems[index].idfMax = stat->elems[i].idf;
}
- stat->nhelems = uniqueHashedElem( stat->helems, stat->nelems);
+ stat->nhelems = uniqueHashedElem( stat->helems, stat->nelems);
}
return stat;
while (StopLow < StopHigh) {
StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
-
+
if ( *StopMiddle == h )
return true;
else if ( *StopMiddle < h )
uint32 *ptr = GETARR(a);
MemSet((void *) sign, 0, sizeof(BITVEC));
- SETBIT(sign, SIGLENBIT); /* set last unused bit */
+ SETBIT(sign, SIGLENBIT); /* set last unused bit */
for (i = 0; i < a->size; i++)
HASH(sign, ptr[i]);
sign = Array2HashedArray(NULL, a);
if ( VARSIZE(sign) > TOAST_INDEX_TARGET )
- { /* make signature due to its big size */
+ { /* make signature due to its big size */
SmlSign *tmpsign;
int len;
makesign(GETSIGN(tmpsign), sign);
tmpsign->size = sizebitvec(GETSIGN(tmpsign));
- tmpsign->maxrepeat = sign->maxrepeat;
+ tmpsign->maxrepeat = sign->maxrepeat;
sign = tmpsign;
}
if ( sign->size == SIGLENBIT )
{
- int32 len = CALCGTSIZE(SIGNKEY | ALLISTRUE, 0);
+ int32 len = CALCGTSIZE(SIGNKEY | ALLISTRUE, 0);
int32 maxrepeat = sign->maxrepeat;
sign = (SmlSign *) palloc(len);
entry->offset, FALSE);
}
}
-
+
PG_RETURN_POINTER(retval);
}
Datum
gsmlsign_decompress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- SmlSign *key = (SmlSign*)DatumGetPointer(PG_DETOAST_DATUM(entry->key));
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ SmlSign *key = (SmlSign*)DatumGetPointer(PG_DETOAST_DATUM(entry->key));
if (key != (SmlSign *) DatumGetPointer(entry->key))
{
if (ISSIGNKEY(add))
{
- BITVECP sadd = GETSIGN(add);
+ BITVECP sadd = GETSIGN(add);
if (ISALLTRUE(add))
return true;
}
else
{
- uint32 *ptr = GETARR(add);
+ uint32 *ptr = GETARR(add);
for (i = 0; i < add->size; i++)
HASH(sbase, ptr[i]);
gsmlsign_union(PG_FUNCTION_ARGS)
{
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- int *size = (int *) PG_GETARG_POINTER(1);
- BITVEC base;
+ int *size = (int *) PG_GETARG_POINTER(1);
+ BITVEC base;
int32 i,
len,
maxrepeat = 1;
result->flag = flag;
result->maxrepeat = maxrepeat;
- if (!ISALLTRUE(result))
+ if (!ISALLTRUE(result))
{
memcpy((void *) GETSIGN(result), (void *) base, sizeof(BITVEC));
result->size = sizebitvec(GETSIGN(result));
}
else
- result->size = SIGLENBIT;
+ result->size = SIGLENBIT;
PG_RETURN_POINTER(result);
}
static int
hemdistsign(BITVECP a, BITVECP b)
{
- int i,
- diff,
- dist = 0;
+ int i,
+ diff,
+ dist = 0;
LOOPBYTE
{
}
return dist;
}
-
+
static int
hemdist(SmlSign *a, SmlSign *b)
{
Datum
gsmlsign_penalty(PG_FUNCTION_ARGS)
{
- GISTENTRY *origentry = (GISTENTRY *) PG_GETARG_POINTER(0); /* always ISSIGNKEY */
- GISTENTRY *newentry = (GISTENTRY *) PG_GETARG_POINTER(1);
- float *penalty = (float *) PG_GETARG_POINTER(2);
- SmlSign *origval = (SmlSign *) DatumGetPointer(origentry->key);
- SmlSign *newval = (SmlSign *) DatumGetPointer(newentry->key);
- BITVECP orig = GETSIGN(origval);
+ GISTENTRY *origentry = (GISTENTRY *) PG_GETARG_POINTER(0); /* always ISSIGNKEY */
+ GISTENTRY *newentry = (GISTENTRY *) PG_GETARG_POINTER(1);
+ float *penalty = (float *) PG_GETARG_POINTER(2);
+ SmlSign *origval = (SmlSign *) DatumGetPointer(origentry->key);
+ SmlSign *newval = (SmlSign *) DatumGetPointer(newentry->key);
+ BITVECP orig = GETSIGN(origval);
*penalty = 0.0;
if (ISARRKEY(newval))
{
- BITVEC sign;
+ BITVEC sign;
makesign(sign, newval);
typedef struct
{
- bool allistrue;
- int32 size;
- BITVEC sign;
+ bool allistrue;
+ int32 size;
+ BITVEC sign;
} CACHESIGN;
static void
fillcache(CACHESIGN *item, SmlSign *key)
{
- item->allistrue = false;
+ item->allistrue = false;
item->size = key->size;
- if (ISARRKEY(key))
+ if (ISARRKEY(key))
{
makesign(item->sign, key);
- item->size = sizebitvec( item->sign );
- }
+ item->size = sizebitvec( item->sign );
+ }
else if (ISALLTRUE(key))
item->allistrue = true;
else
typedef struct
{
OffsetNumber pos;
- int32 cost;
+ int32 cost;
} SPLITCOST;
static int
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
OffsetNumber k,
j;
- SmlSign *datum_l,
+ SmlSign *datum_l,
*datum_r;
- BITVECP union_l,
+ BITVECP union_l,
union_r;
- int32 size_alpha,
+ int32 size_alpha,
size_beta;
- int32 size_waste,
+ int32 size_waste,
waste = -1;
- int32 nbytes;
+ int32 nbytes;
OffsetNumber seed_1 = 0,
seed_2 = 0;
OffsetNumber *left,
*right;
OffsetNumber maxoff;
- BITVECP ptr;
- int i;
+ BITVECP ptr;
+ int i;
CACHESIGN *cache;
SPLITCOST *costvector;
cache = (CACHESIGN *) palloc(sizeof(CACHESIGN) * (maxoff + 2));
fillcache(&cache[FirstOffsetNumber], GETENTRY(entryvec, FirstOffsetNumber));
- for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k))
+ for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k))
{
for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j))
{
datum_l = (SmlSign *) palloc(CALCGTSIZE(SIGNKEY | ALLISTRUE, 0));
SET_VARSIZE(datum_l, CALCGTSIZE(SIGNKEY | ALLISTRUE, 0));
datum_l->flag = SIGNKEY | ALLISTRUE;
- datum_l->size = SIGLENBIT;
+ datum_l->size = SIGLENBIT;
}
else
{
gsmlsign_consistent(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- bool *recheck = (bool *) PG_GETARG_POINTER(4);
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+ bool *recheck = (bool *) PG_GETARG_POINTER(4);
ArrayType *a;
SmlSign *key = (SmlSign*)DatumGetPointer(entry->key);
int res = false;
}
else if (ISARRKEY(key))
{
- uint32 *kptr = GETARR(key),
- *qptr = GETARR(query);
+ uint32 *kptr = GETARR(key),
+ *qptr = GETARR(query);
while( kptr - GETARR(key) < key->size && qptr - GETARR(query) < query->size )
{
}
else if (ISARRKEY(key))
{
- uint32 *kptr = GETARR(key),
- *qptr = GETARR(query);
+ uint32 *kptr = GETARR(key),
+ *qptr = GETARR(query);
Assert( GIST_LEAF(entry) );
if ( ((double)Min(key->size, s->nelems)) / power >= GetSmlarLimit() )
{
- int cnt = 0;
+ int cnt = 0;
while( kptr - GETARR(key) < key->size && qptr - GETARR(query) < query->size )
{
qptr++;
}
}
-
+
if ( ((double)cnt) / power >= GetSmlarLimit() )
res = true;
}
sumQ = 0.0,
sumK = 0.0;
double maxKTF = getIdfMaxLimit(key);
-
+
Assert( s->df );
if ( stat->info != s->info )
elog(ERROR,"Statistic and actual argument have different type");
break;
case ST_COSINE:
{
- double power;
+ double power;
power = sqrt( ((double)(key->size)) * ((double)(s->nelems)) );
for(i=0; i<s->nelems; i++)
count += GETBIT(sign, HASHVAL(s->hash[i]));
-
+
if ( ((double)count) / power >= GetSmlarLimit() )
res = true;
}
sumQ = 0.0,
minK = -1.0;
double maxKTF = getIdfMaxLimit(key);
-
+
Assert( s->df );
if ( stat->info != s->info )
elog(ERROR,"Statistic and actual argument have different type");
{
for(i=0; i<s->nelems; i++)
count += GETBIT(sign, HASHVAL(s->hash[i]));
-
+
if ( s->nelems == count || sqrt(((double)count) / ((double)(s->nelems))) >= GetSmlarLimit() )
res = true;
}
static int smlar_smltype = ST_COSINE;
static const struct config_enum_entry SmlarTypeOptions[] = {
- {"cosine", ST_COSINE, false},
+ {"cosine", ST_COSINE, false},
{"tfidf", ST_TFIDF, false},
{"overlap", ST_OVERLAP, false},
{NULL, 0, false}
static int smlar_tf_method = TF_N;
static const struct config_enum_entry SmlarTFOptions[] = {
- {"n", TF_N, false},
+ {"n", TF_N, false},
{"log", TF_LOG, false},
{"const", TF_CONST, false},
{NULL, 0, false}
}
PG_FUNCTION_INFO_V1(set_smlar_limit);
-Datum set_smlar_limit(PG_FUNCTION_ARGS);
+Datum set_smlar_limit(PG_FUNCTION_ARGS);
Datum
set_smlar_limit(PG_FUNCTION_ARGS)
{
- float4 nlimit = PG_GETARG_FLOAT4(0);
- char buf[32];
+ float4 nlimit = PG_GETARG_FLOAT4(0);
+ char buf[32];
/* init smlar guc */
initSmlarGUC();
}
PG_FUNCTION_INFO_V1(show_smlar_limit);
-Datum show_smlar_limit(PG_FUNCTION_ARGS);
+Datum show_smlar_limit(PG_FUNCTION_ARGS);
Datum
show_smlar_limit(PG_FUNCTION_ARGS)
{
if (PersistentDocStat && GetSmlarUsePersistent())
return PersistentDocStat;
else {
- int stat;
+ int stat;
char buf[1024];
const char *tbl = GetSmlarTable();
StatCache *cache = NULL;
if ( tbl == NULL || *tbl == '\0' )
elog(ERROR,"smlar.stattable is not defined");
- sprintf(buf,"SELECT * FROM \"%s\" ORDER BY 1;", tbl);
+ sprintf(buf,"SELECT * FROM \"%s\" ORDER BY 1;", tbl);
SPI_connect();
stat = SPI_execute(buf, true, 0);
}
else
{
- int i;
+ int i;
double totaldocs = 0.0;
Oid ndocType = SPI_gettypeid(SPI_tuptable->tupdesc, 2);
for(i=0; i<SPI_processed; i++)
{
bool isnullvalue, isnullndoc;
- Datum datum = SPI_getbinval(SPI_tuptable->vals[i], SPI_tuptable->tupdesc, 1, &isnullvalue);
+ Datum datum = SPI_getbinval(SPI_tuptable->vals[i], SPI_tuptable->tupdesc, 1, &isnullvalue);
int64 ndoc;
if (ndocType == INT4OID)
else
{
size_t size = datumGetSize(datum, false, cache->info->typlen);
-
+
cache->elems[i].datum = PointerGetDatum(cacheAlloc(ctx, size));
memcpy(DatumGetPointer(cache->elems[i].datum), DatumGetPointer(datum), size);
}
if ( totaldocs <= 0)
elog(ERROR,"Total number of document is unknown");
cache->nelems = SPI_processed - 1;
-
+
for(i=0;i<cache->nelems;i++)
{
if ( totaldocs < cache->elems[i].idf )