本文整理匯總了C++中ARR_ELEMTYPE函數的典型用法代碼示例。如果您正苦於以下問題:C++ ARR_ELEMTYPE函數的具體用法?C++ ARR_ELEMTYPE怎麽用?C++ ARR_ELEMTYPE使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ARR_ELEMTYPE函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: ginarrayextract
/*
* extractValue support function
*/
Datum
ginarrayextract(PG_FUNCTION_ARGS)
{
/* Make copy of array input to ensure it doesn't disappear while in use */
ArrayType *array = PG_GETARG_ARRAYTYPE_P_COPY(0);
int32 *nkeys = (int32 *) PG_GETARG_POINTER(1);
bool **nullFlags = (bool **) PG_GETARG_POINTER(2);
int16 elmlen;
bool elmbyval;
char elmalign;
Datum *elems;
bool *nulls;
int nelems;
get_typlenbyvalalign(ARR_ELEMTYPE(array),
&elmlen, &elmbyval, &elmalign);
deconstruct_array(array,
ARR_ELEMTYPE(array),
elmlen, elmbyval, elmalign,
&elems, &nulls, &nelems);
*nkeys = nelems;
*nullFlags = nulls;
/* we should not free array, elems[i] points into it */
PG_RETURN_POINTER(elems);
}
示例2: ginqueryarrayextract
/*
* extractQuery support function
*/
Datum
ginqueryarrayextract(PG_FUNCTION_ARGS)
{
/* Make copy of array input to ensure it doesn't disappear while in use */
ArrayType *array = PG_GETARG_ARRAYTYPE_P_COPY(0);
int32 *nkeys = (int32 *) PG_GETARG_POINTER(1);
StrategyNumber strategy = PG_GETARG_UINT16(2);
/* bool **pmatch = (bool **) PG_GETARG_POINTER(3); */
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
bool **nullFlags = (bool **) PG_GETARG_POINTER(5);
int32 *searchMode = (int32 *) PG_GETARG_POINTER(6);
int16 elmlen;
bool elmbyval;
char elmalign;
Datum *elems;
bool *nulls;
int nelems;
get_typlenbyvalalign(ARR_ELEMTYPE(array),
&elmlen, &elmbyval, &elmalign);
deconstruct_array(array,
ARR_ELEMTYPE(array),
elmlen, elmbyval, elmalign,
&elems, &nulls, &nelems);
*nkeys = nelems;
*nullFlags = nulls;
switch (strategy)
{
case GinOverlapStrategy:
*searchMode = GIN_SEARCH_MODE_DEFAULT;
break;
case GinContainsStrategy:
if (nelems > 0)
*searchMode = GIN_SEARCH_MODE_DEFAULT;
else /* everything contains the empty set */
*searchMode = GIN_SEARCH_MODE_ALL;
break;
case GinContainedStrategy:
/* empty set is contained in everything */
*searchMode = GIN_SEARCH_MODE_INCLUDE_EMPTY;
break;
case GinEqualStrategy:
if (nelems > 0)
*searchMode = GIN_SEARCH_MODE_DEFAULT;
else
*searchMode = GIN_SEARCH_MODE_INCLUDE_EMPTY;
break;
default:
elog(ERROR, "ginqueryarrayextract: unknown strategy number: %d",
strategy);
}
/* we should not free array, elems[i] points into it */
PG_RETURN_POINTER(elems);
}
示例3: cword_count
Datum cword_count(PG_FUNCTION_ARGS)
{
ArrayType * count_arr, * doc_arr, * topics_arr;
int32 * count, * doc, * topics;
int32 doclen, num_topics, dsize, i;
Datum * array;
int32 idx;
if (!(fcinfo->context && IsA(fcinfo->context, AggState)))
elog(ERROR, "cword_count not used as part of an aggregate");
doclen = PG_GETARG_INT32(3);
num_topics = PG_GETARG_INT32(4);
dsize = PG_GETARG_INT32(5);
/* Construct a zero'd array at the first call of this function */
if (PG_ARGISNULL(0)) {
array = palloc0(dsize*num_topics*sizeof(Datum));
count_arr =
construct_array(array,dsize*num_topics,INT4OID,4,true,'i');
} else {
count_arr = PG_GETARG_ARRAYTYPE_P(0);
}
doc_arr = PG_GETARG_ARRAYTYPE_P(1);
topics_arr = PG_GETARG_ARRAYTYPE_P(2);
/* Check that the input arrays are of the right dimension and type */
if (ARR_NDIM(count_arr) != 1 || ARR_ELEMTYPE(count_arr) != INT4OID ||
ARR_NDIM(doc_arr) != 1 || ARR_ELEMTYPE(doc_arr) != INT4OID ||
ARR_NDIM(topics_arr) != 1 || ARR_ELEMTYPE(topics_arr) != INT4OID)
ereport
(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("transition function \"%s\" called with invalid parameters",
format_procedure(fcinfo->flinfo->fn_oid))));
count = (int32 *)ARR_DATA_PTR(count_arr);
doc = (int32 *)ARR_DATA_PTR(doc_arr);
topics = (int32 *)ARR_DATA_PTR(topics_arr);
/* Update the word-topic count */
for (i=0; i!=doclen; i++) {
idx = (doc[i]-1) * num_topics + (topics[i]-1);
if (idx < 0 || idx >= dsize*num_topics)
ereport
(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("function \"%s\" called with invalid parameters",
format_procedure(fcinfo->flinfo->fn_oid))));
count[idx]++;
}
PG_RETURN_BYTEA_P(count_arr);
}
示例4: alpine_miner_kmeans_distance_result
Datum
alpine_miner_kmeans_distance_result(PG_FUNCTION_ARGS)
{
ArrayType *sample_arg, *data_arg;
Datum *sample_data, *data_data;
Oid sample_eltype,data_eltype;
int16 sample_typlen, data_typlen;
bool sample_typbyval, data_typbyval;
char sample_typalign, data_typalign;
bool *sample_nulls, *data_nulls;
int sample_count, data_count,k,distanceMode;
float len;
if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2)||PG_ARGISNULL(3) )
{
PG_RETURN_NULL();
}
/* get sample_arg args */
sample_arg=PG_GETARG_ARRAYTYPE_P(0);
/* get sample_arg array element type */
sample_eltype = ARR_ELEMTYPE(sample_arg);
get_typlenbyvalalign(sample_eltype, &sample_typlen, &sample_typbyval, &sample_typalign);
deconstruct_array(sample_arg, sample_eltype,
sample_typlen, sample_typbyval, sample_typalign,
&sample_data, &sample_nulls, &sample_count);
/* get data_arg args */
data_arg = PG_GETARG_ARRAYTYPE_P(1);
/* get data_arg array element type */
data_eltype = ARR_ELEMTYPE(data_arg);
get_typlenbyvalalign(data_eltype, &data_typlen, &data_typbyval, &data_typalign);
deconstruct_array(data_arg, data_eltype,
data_typlen, data_typbyval, data_typalign,
&data_data, &data_nulls, &data_count);
k=PG_GETARG_INT32(2);
distanceMode=PG_GETARG_INT32(3);
len=alpine_miner_resultEuclideanDistance(sample_data,sample_count,data_data,data_count,k,distanceMode);
pfree(sample_data);
pfree(sample_nulls);
pfree(data_data);
pfree(data_nulls);
PG_RETURN_FLOAT8(len);
}
示例5: pcpoint_from_double_array
Datum pcpoint_from_double_array(PG_FUNCTION_ARGS)
{
uint32 pcid = PG_GETARG_INT32(0);
ArrayType *arrptr = PG_GETARG_ARRAYTYPE_P(1);
int nelems;
float8 *vals;
PCPOINT *pt;
PCSCHEMA *schema = pc_schema_from_pcid(pcid, fcinfo);
SERIALIZED_POINT *serpt;
if ( ! schema )
elog(ERROR, "unable to load schema for pcid = %d", pcid);
if ( ARR_ELEMTYPE(arrptr) != FLOAT8OID )
elog(ERROR, "array must be of float8[]");
if ( ARR_NDIM(arrptr) != 1 )
elog(ERROR, "float8[] must have only one dimension");
if ( ARR_HASNULL(arrptr) )
elog(ERROR, "float8[] must not have null elements");
nelems = ARR_DIMS(arrptr)[0];
if ( nelems != schema->ndims || ARR_LBOUND(arrptr)[0] > 1 )
elog(ERROR, "array dimensions do not match schema dimensions of pcid = %d", pcid);
vals = (float8*) ARR_DATA_PTR(arrptr);
pt = pc_point_from_double_array(schema, vals, nelems);
serpt = pc_point_serialize(pt);
pc_point_free(pt);
PG_RETURN_POINTER(serpt);
}
示例6: int2vectorrecv
/*
* int2vectorrecv - converts external binary format to int2vector
*/
Datum
int2vectorrecv(PG_FUNCTION_ARGS)
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
FunctionCallInfoData locfcinfo;
int2vector *result;
/*
* Normally one would call array_recv() using DirectFunctionCall3, but
* that does not work since array_recv wants to cache some data using
* fcinfo->flinfo->fn_extra. So we need to pass it our own flinfo
* parameter.
*/
InitFunctionCallInfoData(locfcinfo, fcinfo->flinfo, 3, NULL, NULL);
locfcinfo.arg[0] = PointerGetDatum(buf);
locfcinfo.arg[1] = ObjectIdGetDatum(INT2OID);
locfcinfo.arg[2] = Int32GetDatum(-1);
locfcinfo.argnull[0] = false;
locfcinfo.argnull[1] = false;
locfcinfo.argnull[2] = false;
result = (int2vector *) DatumGetPointer(array_recv(&locfcinfo));
Assert(!locfcinfo.isnull);
/* sanity checks: int2vector must be 1-D, no nulls */
if (ARR_NDIM(result) != 1 ||
ARR_HASNULL(result) ||
ARR_ELEMTYPE(result) != INT2OID)
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid int2vector data")));
PG_RETURN_POINTER(result);
}
示例7: array_loop
void array_loop(ArrayType *array, int32 start, array_iter *iter)
{
iter->array = array;
iter->ptr = ARR_DATA_PTR(array);
iter->max = ARR_DIMS(array)[0];
get_typlenbyvalalign(ARR_ELEMTYPE(array),
&iter->typlen,
&iter->typbyval,
&iter->typalign);
/* If we are starting in the middle of the array, then scan forward */
start = start - ARR_LBOUND(array)[0];
if (start <= 0)
iter->index = start;
else
{
/*
* could probably be more efficient for fixed length arrays, but
* they would still require adjustments for nulls.
*/
iter->index = 0;
while (start--)
{
Datum d;
bool isna;
array_next(iter, &d, &isna);
}
}
}
示例8: dump_bvf1_inputs
void dump_bvf1_inputs(ArrayType *broker_list_p, text *sector_name_p) {
int ndim, nitems;
int *dim;
int16 typlen;
bool typbyval;
char typalign;
int i;
char *broker_list;
ndim = ARR_NDIM(broker_list_p);
dim = ARR_DIMS(broker_list_p);
nitems = ArrayGetNItems(ndim, dim);
get_typlenbyvalalign(ARR_ELEMTYPE(broker_list_p), &typlen, &typbyval,
&typalign);
broker_list = ARR_DATA_PTR(broker_list_p);
elog(NOTICE, "BVF1: INPUTS START");
for (i = 0; i < nitems; i++) {
elog(NOTICE, "BVF1: broker_list[%d] %s", i,
DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(broker_list))));
broker_list = att_addlength_pointer(broker_list, typlen,
broker_list);
broker_list = (char *) att_align_nominal(broker_list, typalign);
}
elog(NOTICE, "BVF1: sector_name %s",
DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(sector_name_p))));
elog(NOTICE, "BVF1: INPUTS END");
}
示例9: new_intArrayType
/* Create a new int array with room for "num" elements */
ArrayType *
new_intArrayType(int num)
{
ArrayType *r;
int nbytes;
/* if no elements, return a zero-dimensional array */
if (num <= 0)
{
r = construct_empty_array(INT4OID);
return r;
}
nbytes = ARR_OVERHEAD_NONULLS(1) + sizeof(int) * num;
r = (ArrayType *) palloc0(nbytes);
SET_VARSIZE(r, nbytes);
ARR_NDIM(r) = 1;
r->dataoffset = 0; /* marker for no null bitmap */
ARR_ELEMTYPE(r) = INT4OID;
ARR_DIMS(r)[0] = num;
ARR_LBOUND(r)[0] = 1;
return r;
}
示例10: createArrayType
ArrayType* createArrayType(jsize nElems, size_t elemSize, Oid elemType, bool withNulls)
{
ArrayType* v;
Size nBytes = elemSize * nElems;
MemoryContext currCtx = Invocation_switchToUpperContext();
Size dataoffset;
if(withNulls)
{
dataoffset = ARR_OVERHEAD_WITHNULLS(1, nElems);
nBytes += dataoffset;
}
else
{
dataoffset = 0; /* marker for no null bitmap */
nBytes += ARR_OVERHEAD_NONULLS(1);
}
v = (ArrayType*)palloc0(nBytes);
AssertVariableIsOfType(v->dataoffset, int32);
v->dataoffset = (int32)dataoffset;
MemoryContextSwitchTo(currCtx);
SET_VARSIZE(v, nBytes);
ARR_NDIM(v) = 1;
ARR_ELEMTYPE(v) = elemType;
*((int*)ARR_DIMS(v)) = nElems;
*((int*)ARR_LBOUND(v)) = 1;
return v;
}
示例11: svec_cast_float8arr
Datum
svec_cast_float8arr(PG_FUNCTION_ARGS) {
ArrayType *A_PG = PG_GETARG_ARRAYTYPE_P(0);
SvecType *output_svec;
if (ARR_ELEMTYPE(A_PG) != FLOAT8OID)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("svec_cast_float8arr only defined over float8[]")));
if (ARR_NDIM(A_PG) != 1)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("svec_cast_float8arr only defined over 1 dimensional arrays"))
);
if (ARR_NULLBITMAP(A_PG))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("svec_cast_float8arr does not allow null bitmaps on arrays"))
);
/* Extract array */
{
int dimension = ARR_DIMS(A_PG)[0];
float8 *array = (float8 *)ARR_DATA_PTR(A_PG);
/* Create the output SVEC */
SparseData sdata = float8arr_to_sdata(array,dimension);
output_svec = svec_from_sparsedata(sdata,true);
}
PG_RETURN_SVECTYPE_P(output_svec);
}
示例12: cms_topn_frequency
/*
* cms_topn_frequency is a user-facing UDF which returns the estimated frequency
* of an item. The first parameter is for CmsTopn and second is for the item to
* return the frequency.
*/
Datum
cms_topn_frequency(PG_FUNCTION_ARGS)
{
CmsTopn *cmsTopn = (CmsTopn *) PG_GETARG_VARLENA_P(0);
ArrayType *topnArray = TopnArray(cmsTopn);
Datum item = PG_GETARG_DATUM(1);
Oid itemType = get_fn_expr_argtype(fcinfo->flinfo, 1);
TypeCacheEntry *itemTypeCacheEntry = NULL;
Frequency frequency = 0;
if (itemType == InvalidOid)
{
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("could not determine input data types")));
}
if (topnArray != NULL && itemType != ARR_ELEMTYPE(topnArray))
{
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("Not proper type for this cms_topn")));
}
itemTypeCacheEntry = lookup_type_cache(itemType, 0);
frequency = CmsTopnEstimateItemFrequency(cmsTopn, item, itemTypeCacheEntry);
PG_RETURN_INT32(frequency);
}
示例13: pivot_find
/*
* pivot_find() - Searchs an array of labels for a matching value.
*
* Returns: index of found value, or -1 if not found
*
* It may eventually do something smarter than a linear scan, but
* for now this is sufficient given that we don't know anything about the
* order of 'labels'.
*
*/
static int pivot_find(ArrayType *labels, text *attr)
{
char *labelsp;
int i, nelem, asize;
int16 typlen;
bool typbyval;
char typalign;
if (ARR_ELEMTYPE(labels) != TEXTOID)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("pivot_accum: labels are not type text")));
/* Text alignment properties */
get_typlenbyvalalign(TEXTOID, &typlen, &typbyval, &typalign);
/* Get the size of the input attribute, we'll use this for fast compares */
asize = VARSIZE(attr);
/* The labels array is an array of varying length text, scan it adding
the length of the previous entry until we are done or we have found
a match. */
labelsp = (char *) ARR_DATA_PTR(labels);
nelem = ARR_DIMS(labels)[0];
for (i = 0; i < nelem; i++)
{
int lsize = VARSIZE(labelsp);
if (asize == lsize && !memcmp(attr, labelsp, lsize))
return i; /* Found */
labelsp = labelsp + lsize;
labelsp = (char*) att_align(labelsp, typalign);
}
return -1; /* Not found */
}
示例14: array_quantile
Datum array_quantile(PG_FUNCTION_ARGS) {
// The formal PostgreSQL array object
ArrayType *array;
// The array element type
Oid arrayElementType;
// The array element type width
int16 arrayElementTypeWidth;
// The array element type "is passed by value" flags (not used, should always be true)
bool arrayElementTypeByValue;
// The array element type alignment codes (not used)
char arrayElementTypeAlignmentCode;
// The array contents, as PostgreSQL "datum" objects
Datum *arrayContent;
// List of "is null" flags for the array contents
bool *arrayNullFlags;
// The size of each array
int arrayLength;
int i,j, nelem;
double median, mad, f, quantile;
double *inarray;
if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
ereport(ERROR, (errmsg("Null arrays not accepted")));
// Get array and quantile from input
array = PG_GETARG_ARRAYTYPE_P(0);
f = PG_GETARG_FLOAT8(1);
if (ARR_NDIM(array) != 1)
ereport(ERROR, (errmsg("One-dimesional arrays are required")));
if (array_contains_nulls(array))
ereport(ERROR, (errmsg("Array contains null elements")));
arrayLength = (ARR_DIMS(array))[0];
arrayElementType = ARR_ELEMTYPE(array);
get_typlenbyvalalign(arrayElementType, &arrayElementTypeWidth, &arrayElementTypeByValue, &arrayElementTypeAlignmentCode);
deconstruct_array(array, arrayElementType, arrayElementTypeWidth, arrayElementTypeByValue, arrayElementTypeAlignmentCode, &arrayContent, &arrayNullFlags, &arrayLength);
inarray = (double*)malloc(arrayLength*sizeof(double));
for (i=0; i<arrayLength; i++) {
inarray[i] = DatumGetFloat4(arrayContent[i]);
}
gsl_sort (inarray, 1, arrayLength);
quantile = gsl_stats_quantile_from_sorted_data(inarray, 1, arrayLength, f);
PG_RETURN_FLOAT8(quantile);
}
示例15: ginarrayextract
/*
* Function used as extractValue and extractQuery both
*/
Datum
ginarrayextract(PG_FUNCTION_ARGS)
{
ArrayType *array;
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
Datum *entries = NULL;
int16 elmlen;
bool elmbyval;
char elmalign;
/*
* we should guarantee that array will not be destroyed during all
* operation
*/
array = PG_GETARG_ARRAYTYPE_P_COPY(0);
ARRAYCHECK(array);
get_typlenbyvalalign(ARR_ELEMTYPE(array),
&elmlen, &elmbyval, &elmalign);
deconstruct_array(array,
ARR_ELEMTYPE(array),
elmlen, elmbyval, elmalign,
&entries, NULL, (int *) nentries);
if (*nentries == 0 && PG_NARGS() == 3)
{
switch (PG_GETARG_UINT16(2)) /* StrategyNumber */
{
case GinOverlapStrategy:
*nentries = -1; /* nobody can be found */
break;
case GinContainsStrategy:
case GinContainedStrategy:
case GinEqualStrategy:
default: /* require fullscan: GIN can't find void
* arrays */
break;
}
}
/* we should not free array, entries[i] points into it */
PG_RETURN_POINTER(entries);
}