@@ -1020,13 +1020,11 @@ smoc_spoly(PG_FUNCTION_ARGS)
10201020
10211021/* GIN index ***********************************/
10221022
1023- Datum
1024- smoc_gin_extract_value ( PG_FUNCTION_ARGS )
1023+ static Datum
1024+ smoc_gin_extract_internal ( Smoc * moc_a , int32 * nkeys , int gin_order )
10251025{
1026- Smoc * moc_a = (Smoc * )PG_DETOAST_DATUM (PG_GETARG_DATUM (0 ));
10271026char * moc_a_base = MOC_BASE (moc_a );
10281027int32 moc_a_end = VARSIZE (moc_a )- VARHDRSZ ;
1029- int32 * nkeys = (int32 * )PG_GETARG_POINTER (1 );
10301028int32 nalloc = 4 ;
10311029Datum * keys = palloc (nalloc * sizeof (Datum ));
10321030
@@ -1036,7 +1034,7 @@ smoc_gin_extract_value(PG_FUNCTION_ARGS)
10361034{
10371035moc_interval * x = MOC_INTERVAL (moc_a_base ,a );
10381036
1039- int shift = 2 * (HEALPIX_MAX_ORDER - MOC_GIN_ORDER );// degrade to MOC_GIN_ORDER
1037+ int shift = 2 * (HEALPIX_MAX_ORDER - gin_order );// degrade to MOC_GIN_ORDER
10401038int32 first = (x -> first >>shift );// set low bits to zero
10411039hpint64 low_bits_one = (1L <<shift )- 1 ;
10421040int32 second = ((x -> second + low_bits_one ) >>shift );// round low bits up
@@ -1060,49 +1058,27 @@ smoc_gin_extract_value(PG_FUNCTION_ARGS)
10601058PG_RETURN_POINTER (keys );
10611059}
10621060
1061+ Datum
1062+ smoc_gin_extract_value (PG_FUNCTION_ARGS )
1063+ {
1064+ Smoc * moc_a = (Smoc * )PG_DETOAST_DATUM (PG_GETARG_DATUM (0 ));
1065+ int32 * nkeys = (int32 * )PG_GETARG_POINTER (1 );
1066+
1067+ PG_RETURN_DATUM (smoc_gin_extract_internal (moc_a ,nkeys ,MOC_GIN_ORDER ));
1068+ }
1069+
10631070Datum
10641071smoc_gin_extract_query (PG_FUNCTION_ARGS )
10651072{
10661073Smoc * moc_a = (Smoc * )PG_DETOAST_DATUM (PG_GETARG_DATUM (0 ));
1067- char * moc_a_base = MOC_BASE (moc_a );
1068- int32 moc_a_end = VARSIZE (moc_a )- VARHDRSZ ;
10691074int32 * nkeys = (int32 * )PG_GETARG_POINTER (1 );
10701075StrategyNumber st = PG_GETARG_UINT16 (2 );
10711076int32 * searchmode = (int32 * )PG_GETARG_POINTER (6 );
1072- int32 nalloc = 4 ;
1073- Datum * keys = palloc (nalloc * sizeof (Datum ));
1074-
1075- * nkeys = 0 ;
10761077
10771078if (st == MOC_GIN_STRATEGY_SUBSET )
10781079* searchmode = GIN_SEARCH_MODE_INCLUDE_EMPTY ;
10791080
1080- for (int32 a = moc_a -> data_begin ;a < moc_a_end ;a = next_interval (a ))
1081- {
1082- moc_interval * x = MOC_INTERVAL (moc_a_base ,a );
1083-
1084- int shift = 2 * (HEALPIX_MAX_ORDER - MOC_GIN_ORDER );// degrade to MOC_GIN_ORDER
1085- int32 first = (x -> first >>shift );// set low bits to zero
1086- hpint64 low_bits_one = (1L <<shift )- 1 ;
1087- int32 second = ((x -> second + low_bits_one ) >>shift );// round low bits up
1088- Assert (shift > 32 );// internal GIN datatype isn't 64 bits
1089-
1090- // split interval into individual pixels of order MOC_GIN_ORDER
1091- for (int32 p = first ;p < second ;p ++ )
1092- {
1093- if (* nkeys > 0 && keys [* nkeys - 1 ]== p )// has (larger) pixel already been added?
1094- continue ;
1095- if (* nkeys >=nalloc )
1096- {
1097- nalloc *=2 ;
1098- Assert (nalloc < 1000000 );
1099- keys = repalloc (keys ,nalloc * sizeof (Datum ));
1100- }
1101- keys [(* nkeys )++ ]= Int32GetDatum (p );
1102- }
1103- }
1104-
1105- PG_RETURN_POINTER (keys );
1081+ PG_RETURN_DATUM (smoc_gin_extract_internal (moc_a ,nkeys ,MOC_GIN_ORDER ));
11061082}
11071083
11081084Datum