1 fix various comparing functions
authorTeodor Sigaev <teodor@sigaev.ru>
Thu, 31 Mar 2005 15:08:08 +0000 (15:08 +0000)
committerTeodor Sigaev <teodor@sigaev.ru>
Thu, 31 Mar 2005 15:08:08 +0000 (15:08 +0000)
2 implement gtsvector_out for use with gevel module (debug GiST indexes, http://www.sai.msu.su/~megera/postgres/gist/gevel/)

contrib/tsearch2/dict.c
contrib/tsearch2/gistidx.c
contrib/tsearch2/rank.c
contrib/tsearch2/ts_cfg.c
contrib/tsearch2/tsvector.c
contrib/tsearch2/wparser.c

index 7a3626b3bc9934c5590ea2188b9931a1d04086b8..0b7fb7288c6dc73b95665291cc6e0bcd12c065fc 100644 (file)
@@ -92,7 +92,9 @@ reset_dict(void)
 static int
 comparedict(const void *a, const void *b)
 {
-   return ((DictInfo *) a)->dict_id - ((DictInfo *) b)->dict_id;
+   if ( ((DictInfo *) a)->dict_id == ((DictInfo *) b)->dict_id )
+       return 0;
+   return ( ((DictInfo *) a)->dict_id < ((DictInfo *) b)->dict_id ) ? -1 : 1;
 }
 
 DictInfo *
index bf1705036e4444f3fe2d9742f5b3f656f8a82ff4..58fbb974512e0ae84c55072027bc61de62bfe90c 100644 (file)
@@ -54,6 +54,7 @@ Datum     gtsvector_picksplit(PG_FUNCTION_ARGS);
    GETBITBYTE(val,7)   \
 )
 
+static int4 sizebitvec(BITVECP sign);
 
 Datum
 gtsvector_in(PG_FUNCTION_ARGS)
@@ -64,13 +65,31 @@ gtsvector_in(PG_FUNCTION_ARGS)
    PG_RETURN_DATUM(0);
 }
 
+#define    SINGOUTSTR  "%d true bits, %d false bits"
+#define    ARROUTSTR   "%d unique words"
+#define EXTRALEN   ( 2*13 )
+
+static int outbuf_maxlen = 0;
+
 Datum
 gtsvector_out(PG_FUNCTION_ARGS)
 {
-   ereport(ERROR,
-           (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-            errmsg("gtsvector_out not implemented")));
-   PG_RETURN_DATUM(0);
+   GISTTYPE   *key = (GISTTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_POINTER(0)));
+   char *outbuf;
+
+   if ( outbuf_maxlen==0 )
+       outbuf_maxlen = 2*EXTRALEN + Max( strlen(SINGOUTSTR), strlen(ARROUTSTR) ) + 1;
+   outbuf = palloc( outbuf_maxlen );
+
+   if ( ISARRKEY(key) ) 
+       sprintf( outbuf, ARROUTSTR, ARRNELEM(key) );  
+   else {
+       int cnttrue = ( ISALLTRUE(key) ) ? SIGLENBIT : sizebitvec(GETSIGN(key));
+       sprintf( outbuf, SINGOUTSTR, cnttrue, SIGLENBIT - cnttrue ); 
+   }   
+
+   PG_FREE_IF_COPY(key,0);
+   PG_RETURN_POINTER(outbuf);
 }
 
 static int
index a06bb9679582ebf4cd7085964bdd9730b73cb44f..a58986e474118fd8f04936a0afd00b923aa12ed2 100644 (file)
@@ -386,7 +386,7 @@ static int
 compareDocR(const void *a, const void *b)
 {
    if (((DocRepresentation *) a)->pos == ((DocRepresentation *) b)->pos)
-       return 1;
+       return 0;
    return (((DocRepresentation *) a)->pos > ((DocRepresentation *) b)->pos) ? 1 : -1;
 }
 
@@ -654,7 +654,7 @@ static int
 compareDocWord(const void *a, const void *b)
 {
    if (((DocWord *) a)->pos == ((DocWord *) b)->pos)
-       return 1;
+       return 0;
    return (((DocWord *) a)->pos > ((DocWord *) b)->pos) ? 1 : -1;
 }
 
index 79f25c43d95c54d2e7d7ec84768047619f1ed787..735d406109f1e7194f5a9c2986855127db036e53 100644 (file)
@@ -186,7 +186,9 @@ reset_cfg(void)
 static int
 comparecfg(const void *a, const void *b)
 {
-   return ((TSCfgInfo *) a)->id - ((TSCfgInfo *) b)->id;
+   if ( ((TSCfgInfo *) a)->id == ((TSCfgInfo *) b)->id )
+       return 0;
+   return ( ((TSCfgInfo *) a)->id < ((TSCfgInfo *) b)->id ) ? -1 : 1;
 }
 
 TSCfgInfo *
index 2856a16aba8e71aadee0c657fc29d353703b4cba..2630694e4e626ed81c19db5bbcf643e31005e995 100644 (file)
@@ -51,7 +51,7 @@ static int
 comparePos(const void *a, const void *b)
 {
    if (WEP_GETPOS(*(WordEntryPos *) a) == WEP_GETPOS(*(WordEntryPos *) b))
-       return 1;
+       return 0;
    return (WEP_GETPOS(*(WordEntryPos *) a)> WEP_GETPOS(*(WordEntryPos *) b)) ? 1 : -1;
 }
 
index 554c2684b9bfc2a445b14967e0df049ac7e90a11..33bfd4d87e817523b8917bfa79cf30eae243bf1d 100644 (file)
@@ -93,7 +93,9 @@ reset_prs(void)
 static int
 compareprs(const void *a, const void *b)
 {
-   return ((WParserInfo *) a)->prs_id - ((WParserInfo *) b)->prs_id;
+   if ( ((WParserInfo *) a)->prs_id == ((WParserInfo *) b)->prs_id )
+       return 0;
+   return ( ((WParserInfo *) a)->prs_id < ((WParserInfo *) b)->prs_id ) ? -1 : 1;
 }
 
 WParserInfo *