Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4b105cd

Browse files
committed
fix addInfo array subscripts, remove useless function SimpleArray2Array, refactoring
1 parente4247ef commit4b105cd

File tree

1 file changed

+37
-47
lines changed

1 file changed

+37
-47
lines changed

‎src/rum_arr_utils.c

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@
4141
#defineRUM_SIMILAR_STRATEGY5
4242

4343

44-
#defineLINEAR_LIMIT5
4544
#defineNDIM1
4645

47-
4846
#defineARR_NELEMS(x)ArrayGetNItems(ARR_NDIM(x), ARR_DIMS(x))
49-
#defineARR_ISVOID(x)((x) == NULL || ARR_NELEMS(x) == 0)
47+
#defineARR_ISVOID(x)((x) == NULL || ARR_NELEMS(x) == 0)
5048

5149
#defineCHECKARRVALID(x) \
5250
do { \
@@ -71,6 +69,9 @@
7169
(s)->info = NULL; \
7270
} while (0)
7371

72+
#defineDIST_FROM_SML(sml) \
73+
( (sml == 0.0) ? get_float8_infinity() : ((float8) 1) / ((float8) (sml)) )
74+
7475

7576
typedefstructAnyArrayTypeInfo
7677
{
@@ -128,7 +129,6 @@ static void freeAnyArrayTypeInfo(AnyArrayTypeInfo *info);
128129
staticvoidcmpFuncInit(AnyArrayTypeInfo*info);
129130

130131
staticSimpleArray*Array2SimpleArray(AnyArrayTypeInfo*info,ArrayType*a);
131-
staticArrayType*SimpleArray2Array(SimpleArray*s);
132132
staticvoidfreeSimpleArray(SimpleArray*s);
133133
staticintcmpAscArrayElem(constvoid*a,constvoid*b,void*arg);
134134
staticintcmpDescArrayElem(constvoid*a,constvoid*b,void*arg);
@@ -373,15 +373,19 @@ rum_anyarray_consistent(PG_FUNCTION_ARGS)
373373
if (check[i])
374374
intersection++;
375375

376-
for (i=0;i<nkeys;i++)
377-
if (!addInfoIsNull[0])
378-
{
379-
nentries=DatumGetInt32(addInfo[i]);
380-
break;
381-
}
382-
383-
if (nentries >=0)
376+
if (intersection>0)
384377
{
378+
/* extract array's length from addInfo */
379+
for (i=0;i<nkeys;i++)
380+
if (!addInfoIsNull[i])
381+
{
382+
nentries=DatumGetInt32(addInfo[i]);
383+
break;
384+
}
385+
386+
/* there must be addInfo */
387+
Assert(nentries >=0);
388+
385389
InitDummySimpleArray(&sa,nentries);
386390
InitDummySimpleArray(&sb,nkeys);
387391
res=getSimilarity(&sa,&sb,intersection) >=SmlLimit;
@@ -412,8 +416,7 @@ rum_anyarray_ordering(PG_FUNCTION_ARGS)
412416
Datum*addInfo= (Datum*)PG_GETARG_POINTER(8);
413417
bool*addInfoIsNull= (bool*)PG_GETARG_POINTER(9);
414418

415-
float8dist,
416-
sml;
419+
float8sml;
417420
int32intersection=0,
418421
nentries=-1;
419422
inti;
@@ -424,26 +427,27 @@ rum_anyarray_ordering(PG_FUNCTION_ARGS)
424427
if (check[i])
425428
intersection++;
426429

427-
if (intersection==0)
428-
PG_RETURN_FLOAT8(get_float8_infinity());
430+
if (intersection>0)
431+
{
432+
/* extract array's length from addInfo */
433+
for (i=0;i<nkeys;i++)
434+
if (!addInfoIsNull[i])
435+
{
436+
nentries=DatumGetInt32(addInfo[i]);
437+
break;
438+
}
429439

430-
for (i=0;i<nkeys;i++)
431-
if (!addInfoIsNull[0])
432-
{
433-
nentries=DatumGetInt32(addInfo[i]);
434-
break;
435-
}
440+
/* there must be addInfo */
441+
Assert(nentries >=0);
436442

437-
InitDummySimpleArray(&sa,nentries);
438-
InitDummySimpleArray(&sb,nkeys);
439-
sml=getSimilarity(&sa,&sb,intersection);
443+
InitDummySimpleArray(&sa,nentries);
444+
InitDummySimpleArray(&sb,nkeys);
445+
sml=getSimilarity(&sa,&sb,intersection);
440446

441-
if (sml==0.0)
442-
dist=get_float8_infinity();
443-
else
444-
dist=1.0 /sml;
447+
PG_RETURN_FLOAT8(DIST_FROM_SML(sml));
448+
}
445449

446-
PG_RETURN_FLOAT8(dist);
450+
PG_RETURN_FLOAT8(DIST_FROM_SML(0.0));
447451
}
448452

449453
Datum
@@ -494,7 +498,7 @@ rum_anyarray_distance(PG_FUNCTION_ARGS)
494498
AnyArrayTypeInfo*info;
495499
SimpleArray*sa,
496500
*sb;
497-
float8result=0.0;
501+
float8sml=0.0;
498502

499503
CHECKARRVALID(a);
500504
CHECKARRVALID(b);
@@ -515,19 +519,15 @@ rum_anyarray_distance(PG_FUNCTION_ARGS)
515519
sa=Array2SimpleArray(info,a);
516520
sb=Array2SimpleArray(info,b);
517521

518-
result=getSimilarity(sa,sb,getNumOfIntersect(sa,sb));
519-
if (result==0.0)
520-
result=get_float8_infinity();
521-
else
522-
result=1.0 /result;
522+
sml=getSimilarity(sa,sb,getNumOfIntersect(sa,sb));
523523

524524
freeSimpleArray(sb);
525525
freeSimpleArray(sa);
526526

527527
PG_FREE_IF_COPY(b,1);
528528
PG_FREE_IF_COPY(a,0);
529529

530-
PG_RETURN_FLOAT8(result);
530+
PG_RETURN_FLOAT8(DIST_FROM_SML(sml));
531531
}
532532

533533

@@ -702,16 +702,6 @@ Array2SimpleArray(AnyArrayTypeInfo *info, ArrayType *a)
702702
returns;
703703
}
704704

705-
staticArrayType*
706-
SimpleArray2Array(SimpleArray*s)
707-
{
708-
returnconstruct_array(s->elems,s->nelems,
709-
s->info->typid,
710-
s->info->typlen,
711-
s->info->typbyval,
712-
s->info->typalign);
713-
}
714-
715705
staticvoid
716706
freeSimpleArray(SimpleArray*s)
717707
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp