Skip to content

Commit fb13881

Browse files
committed
1 fix various comparing functions
2 implement gtsvector_out for use with gevel module (debug GiST indexes, http://www.sai.msu.su/~megera/postgres/gist/gevel/)
1 parent fd97743 commit fb13881

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

contrib/tsearch2/dict.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ reset_dict(void)
9292
static int
9393
comparedict(const void *a, const void *b)
9494
{
95-
return ((DictInfo *) a)->dict_id - ((DictInfo *) b)->dict_id;
95+
if ( ((DictInfo *) a)->dict_id == ((DictInfo *) b)->dict_id )
96+
return 0;
97+
return ( ((DictInfo *) a)->dict_id < ((DictInfo *) b)->dict_id ) ? -1 : 1;
9698
}
9799

98100
DictInfo *

contrib/tsearch2/gistidx.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Datum gtsvector_picksplit(PG_FUNCTION_ARGS);
5454
GETBITBYTE(val,7) \
5555
)
5656

57+
static int4 sizebitvec(BITVECP sign);
5758

5859
Datum
5960
gtsvector_in(PG_FUNCTION_ARGS)
@@ -64,13 +65,31 @@ gtsvector_in(PG_FUNCTION_ARGS)
6465
PG_RETURN_DATUM(0);
6566
}
6667

68+
#define SINGOUTSTR "%d true bits, %d false bits"
69+
#define ARROUTSTR "%d unique words"
70+
#define EXTRALEN ( 2*13 )
71+
72+
static int outbuf_maxlen = 0;
73+
6774
Datum
6875
gtsvector_out(PG_FUNCTION_ARGS)
6976
{
70-
ereport(ERROR,
71-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
72-
errmsg("gtsvector_out not implemented")));
73-
PG_RETURN_DATUM(0);
77+
GISTTYPE *key = (GISTTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_POINTER(0)));
78+
char *outbuf;
79+
80+
if ( outbuf_maxlen==0 )
81+
outbuf_maxlen = 2*EXTRALEN + Max( strlen(SINGOUTSTR), strlen(ARROUTSTR) ) + 1;
82+
outbuf = palloc( outbuf_maxlen );
83+
84+
if ( ISARRKEY(key) )
85+
sprintf( outbuf, ARROUTSTR, ARRNELEM(key) );
86+
else {
87+
int cnttrue = ( ISALLTRUE(key) ) ? SIGLENBIT : sizebitvec(GETSIGN(key));
88+
sprintf( outbuf, SINGOUTSTR, cnttrue, SIGLENBIT - cnttrue );
89+
}
90+
91+
PG_FREE_IF_COPY(key,0);
92+
PG_RETURN_POINTER(outbuf);
7493
}
7594

7695
static int

contrib/tsearch2/rank.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ static int
386386
compareDocR(const void *a, const void *b)
387387
{
388388
if (((DocRepresentation *) a)->pos == ((DocRepresentation *) b)->pos)
389-
return 1;
389+
return 0;
390390
return (((DocRepresentation *) a)->pos > ((DocRepresentation *) b)->pos) ? 1 : -1;
391391
}
392392

@@ -654,7 +654,7 @@ static int
654654
compareDocWord(const void *a, const void *b)
655655
{
656656
if (((DocWord *) a)->pos == ((DocWord *) b)->pos)
657-
return 1;
657+
return 0;
658658
return (((DocWord *) a)->pos > ((DocWord *) b)->pos) ? 1 : -1;
659659
}
660660

contrib/tsearch2/ts_cfg.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ reset_cfg(void)
186186
static int
187187
comparecfg(const void *a, const void *b)
188188
{
189-
return ((TSCfgInfo *) a)->id - ((TSCfgInfo *) b)->id;
189+
if ( ((TSCfgInfo *) a)->id == ((TSCfgInfo *) b)->id )
190+
return 0;
191+
return ( ((TSCfgInfo *) a)->id < ((TSCfgInfo *) b)->id ) ? -1 : 1;
190192
}
191193

192194
TSCfgInfo *

contrib/tsearch2/tsvector.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static int
5151
comparePos(const void *a, const void *b)
5252
{
5353
if (WEP_GETPOS(*(WordEntryPos *) a) == WEP_GETPOS(*(WordEntryPos *) b))
54-
return 1;
54+
return 0;
5555
return (WEP_GETPOS(*(WordEntryPos *) a)> WEP_GETPOS(*(WordEntryPos *) b)) ? 1 : -1;
5656
}
5757

contrib/tsearch2/wparser.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ reset_prs(void)
9393
static int
9494
compareprs(const void *a, const void *b)
9595
{
96-
return ((WParserInfo *) a)->prs_id - ((WParserInfo *) b)->prs_id;
96+
if ( ((WParserInfo *) a)->prs_id == ((WParserInfo *) b)->prs_id )
97+
return 0;
98+
return ( ((WParserInfo *) a)->prs_id < ((WParserInfo *) b)->prs_id ) ? -1 : 1;
9799
}
98100

99101
WParserInfo *

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy