Datum HASHAPI_Hash_1_time(PG_FUNCTION_ARGS) { int32 num_segs; /* number of segments */ TimeADT val1; /* time value */ unsigned int targetbucket; /* 0-based */ int16 algorithm; /* hashing algorithm */ Datum d1; Oid oid; /* Get number of segments */ num_segs = PG_GETARG_INT32(0); /* Get hashing algoriithm */ algorithm = PG_GETARG_INT16(1); /* Get the value to hash */ val1 = PG_GETARG_TIMEADT(2); d1 = TimeADTGetDatum(val1); /* create a CdbHash for this hash test. */ h = makeCdbHash(num_segs, algorithm); /* init cdb hash */ cdbhashinit(h); oid = TIMEOID; cdbhash(h, d1, oid); /* reduce the result hash value */ targetbucket = cdbhashreduce(h); PG_RETURN_INT32(targetbucket); /* return target bucket (segID) */ }
/* * Convert a compressed leaf item back to the original type, for index-only * scans. */ GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo) { GISTENTRY *retval; Datum datum; Assert(tinfo->indexsize >= 2 * tinfo->size); /* * Get the original Datum from the stored datum. On leaf entries, the * lower and upper bound are the same. We just grab the lower bound and * return it. */ switch (tinfo->t) { case gbt_t_int2: datum = Int16GetDatum(*(int16 *) entry->key); break; case gbt_t_int4: datum = Int32GetDatum(*(int32 *) entry->key); break; case gbt_t_int8: datum = Int64GetDatum(*(int64 *) entry->key); break; case gbt_t_oid: case gbt_t_enum: datum = ObjectIdGetDatum(*(Oid *) entry->key); break; case gbt_t_float4: datum = Float4GetDatum(*(float4 *) entry->key); break; case gbt_t_float8: datum = Float8GetDatum(*(float8 *) entry->key); break; case gbt_t_date: datum = DateADTGetDatum(*(DateADT *) entry->key); break; case gbt_t_time: datum = TimeADTGetDatum(*(TimeADT *) entry->key); break; case gbt_t_ts: datum = TimestampGetDatum(*(Timestamp *) entry->key); break; case gbt_t_cash: datum = CashGetDatum(*(Cash *) entry->key); break; default: datum = PointerGetDatum(entry->key); } retval = palloc(sizeof(GISTENTRY)); gistentryinit(*retval, datum, entry->rel, entry->page, entry->offset, false); return retval; }
static Datum leftmostvalue_time(void) { return TimeADTGetDatum(0); }