本文整理汇总了C++中construct_array函数的典型用法代码示例。如果您正苦于以下问题:C++ construct_array函数的具体用法?C++ construct_array怎么用?C++ construct_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了construct_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: alpine_plda_first
Datum
alpine_plda_first(PG_FUNCTION_ARGS)
{
ArrayType *assign;
ArrayType *topiccount;
int32 * assign_array_data;
int32 * topiccount_array_data;
Datum values[2];
int32 column_size,topicnumber;
int32 temptopic;
int32 k;
bool * isnulls ;
TupleDesc tuple;
HeapTuple ret;
Datum * arr1;
Datum * arr2;
if (PG_ARGISNULL(0)){
PG_RETURN_NULL();
}
column_size=PG_GETARG_INT32(0);
topicnumber=PG_GETARG_INT32(1);
arr1 = palloc0(column_size * sizeof(Datum));//Datum *
assign = construct_array(arr1,column_size,INT4OID,4,true,'i');
assign_array_data = (int32 *)ARR_DATA_PTR(assign);
arr2 = palloc0(topicnumber * sizeof(Datum));//Datum *
topiccount = construct_array(arr2,topicnumber,INT4OID,4,true,'i');
topiccount_array_data = (int32 *)ARR_DATA_PTR(topiccount);
for ( k = 0; k < column_size; k++){
temptopic = random() % topicnumber + 1;
assign_array_data[k] = temptopic;
topiccount_array_data[temptopic-1]++;
}
values[0] = PointerGetDatum(assign);
values[1] = PointerGetDatum(topiccount);
if (get_call_result_type(fcinfo, NULL, &tuple) != TYPEFUNC_COMPOSITE)
ereport(ERROR,
(errcode( ERRCODE_FEATURE_NOT_SUPPORTED ),
errmsg( "function returning record called in context "
"that cannot accept type record" )));
tuple = BlessTupleDesc(tuple);
isnulls = palloc0(2 * sizeof(bool));
ret = heap_form_tuple(tuple, values, isnulls);
if (isnulls[0] || isnulls[1])
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("function \"%s\" produced null results",
format_procedure(fcinfo->flinfo->fn_oid))));
PG_RETURN_DATUM(HeapTupleGetDatum(ret));
}
示例2: randomTopics
Datum randomTopics(PG_FUNCTION_ARGS)
{
int32 doclen = PG_GETARG_INT32(0);
int32 num_topics = PG_GETARG_INT32(1);
ArrayType * ret_topics_arr, * ret_topic_d_arr;
int32 * ret_topics, * ret_topic_d;
Datum * arr1 = palloc0(doclen * sizeof(Datum));
ret_topics_arr = construct_array(arr1,doclen,INT4OID,4,true,'i');
ret_topics = (int32 *)ARR_DATA_PTR(ret_topics_arr);
Datum * arr2 = palloc0(num_topics * sizeof(Datum));
ret_topic_d_arr = construct_array(arr2,num_topics,INT4OID,4,true,'i');
ret_topic_d = (int32 *)ARR_DATA_PTR(ret_topic_d_arr);
/* Sample topics */
int i, rtopic;
for (i=0; i!=doclen; i++) {
rtopic = random() % num_topics + 1;
ret_topics[i] = rtopic;
ret_topic_d[rtopic-1]++;
}
/* Package up the return arrays */
Datum values[2];
values[0] = PointerGetDatum(ret_topics_arr);
values[1] = PointerGetDatum(ret_topic_d_arr);
TupleDesc tuple;
if (get_call_result_type(fcinfo, NULL, &tuple) != TYPEFUNC_COMPOSITE)
ereport(ERROR,
(errcode( ERRCODE_FEATURE_NOT_SUPPORTED ),
errmsg( "function returning record called in context "
"that cannot accept type record" )));
tuple = BlessTupleDesc(tuple);
bool * isnulls = palloc0(2 * sizeof(bool));
HeapTuple ret = heap_form_tuple(tuple, values, isnulls);
if (isnulls[0] || isnulls[1])
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("function \"%s\" produced null results",
format_procedure(fcinfo->flinfo->fn_oid),i)));
PG_RETURN_DATUM(HeapTupleGetDatum(ret));
}
示例3: lexize
Datum
lexize(PG_FUNCTION_ARGS)
{
text *in = PG_GETARG_TEXT_P(1);
DictInfo *dict;
TSLexeme *res,
*ptr;
Datum *da;
ArrayType *a;
SET_FUNCOID();
dict = finddict(PG_GETARG_OID(0));
ptr = res = (TSLexeme *) DatumGetPointer(
FunctionCall3(&(dict->lexize_info),
PointerGetDatum(dict->dictionary),
PointerGetDatum(VARDATA(in)),
Int32GetDatum(VARSIZE(in) - VARHDRSZ)
)
);
PG_FREE_IF_COPY(in, 1);
if (!res)
{
if (PG_NARGS() > 2)
PG_RETURN_POINTER(NULL);
else
PG_RETURN_NULL();
}
while (ptr->lexeme)
ptr++;
da = (Datum *) palloc(sizeof(Datum) * (ptr - res + 1));
ptr = res;
while (ptr->lexeme)
{
da[ptr - res] = PointerGetDatum(char2text(ptr->lexeme));
ptr++;
}
a = construct_array(
da,
ptr - res,
TEXTOID,
-1,
false,
'i'
);
ptr = res;
while (ptr->lexeme)
{
pfree(DatumGetPointer(da[ptr - res]));
pfree(ptr->lexeme);
ptr++;
}
pfree(res);
pfree(da);
PG_RETURN_POINTER(a);
}
示例4: get_range_by_idx
/*
* Returns N-th range (in form of array)
*
* First argument is the parent relid.
* Second argument is the index of the range (if it is negative then the last
* range will be returned).
*/
Datum
get_range_by_idx(PG_FUNCTION_ARGS)
{
int parent_oid = DatumGetInt32(PG_GETARG_DATUM(0));
int idx = DatumGetInt32(PG_GETARG_DATUM(1));
PartRelationInfo *prel;
RangeRelation *rangerel;
RangeEntry *ranges;
RangeEntry *re;
Datum *elems;
TypeCacheEntry *tce;
prel = get_pathman_relation_info(parent_oid, NULL);
rangerel = get_pathman_range_relation(parent_oid, NULL);
if (!prel || !rangerel || idx >= (int)rangerel->ranges.length)
PG_RETURN_NULL();
tce = lookup_type_cache(prel->atttype, 0);
ranges = dsm_array_get_pointer(&rangerel->ranges);
if (idx >= 0)
re = &ranges[idx];
else
re = &ranges[rangerel->ranges.length - 1];
elems = palloc(2 * sizeof(Datum));
elems[0] = PATHMAN_GET_DATUM(re->min, rangerel->by_val);
elems[1] = PATHMAN_GET_DATUM(re->max, rangerel->by_val);
PG_RETURN_ARRAYTYPE_P(
construct_array(elems, 2, prel->atttype,
tce->typlen, tce->typbyval, tce->typalign));
}
示例5: zero_array
Datum zero_array(PG_FUNCTION_ARGS)
{
int32 len = PG_GETARG_INT32(0);
Datum * array = palloc0(len * sizeof(Datum));
ArrayType * pgarray = construct_array(array, len, INT4OID, 4, true, 'i');
PG_RETURN_ARRAYTYPE_P(pgarray);
}
示例6: stem_token_arr
Datum stem_token_arr(PG_FUNCTION_ARGS)
{
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
/* Prepare elements to receive input text[] */
ArrayType *arr = PG_GETARG_ARRAYTYPE_P(0);
Datum *dtum;
bool *nulls;
int ndim;
/* Deconstruct input text[] */
deconstruct_array(arr, TEXTOID, -1, false, 'i', &dtum, &nulls, &ndim);
/* Prepare stemmer */
struct sb_stemmer *stemmer = sb_stemmer_new(
"english" /* language */, NULL /* language encoding NULL for UTF-8 */);
Assert(stemmer);
/* Call stemming code */
text **result = (text **) palloc(ndim * sizeof(text * ));
for(int i=0; i< ndim; i++) {
text *token = dtum[i] == 0 ? NULL : DatumGetTextP(dtum[i]);
char *empty;
if(token == NULL) {
empty = (char *)palloc(sizeof(char));
empty[0] = '\0';
}
result[i] = (token == NULL ?
cstring_to_text(empty) :
cstring_to_text(stem_token_text(stemmer, token)));
}
ArrayType *res = construct_array((Datum*)result, ndim, TEXTOID, -1, false, 'i');
sb_stemmer_delete(stemmer);
PG_RETURN_ARRAYTYPE_P(res);
}
示例7: postal_normalize
Datum postal_normalize(PG_FUNCTION_ARGS)
{
text *address = PG_GETARG_TEXT_P(0);
size_t arr_nelems, i;
libpostal_normalize_options_t options = libpostal_get_default_options();
char **expansions = libpostal_expand_address(text_to_cstring(address), options, &arr_nelems);
ArrayType *arr;
Datum *arr_elems = palloc(sizeof(Datum) * arr_nelems);
Oid elem_type = TEXTOID;
int16 elem_len;
char elem_byval;
char elem_align;
get_typlenbyvalalign(elem_type, &elem_len, &elem_byval, &elem_align);
for (i = 0; i < arr_nelems; i++)
{
arr_elems[i] = PointerGetDatum(cstring_to_text(expansions[i]));
}
/* Array construction takes a full copy of the input */
arr = construct_array(arr_elems, arr_nelems, elem_type, elem_len, elem_byval, elem_align);
/* Clean up unmanaged memory */
libpostal_expansion_array_destroy(expansions, arr_nelems);
PG_RETURN_ARRAYTYPE_P(arr);
}
示例8: tsvector2textarray
Datum
tsvector2textarray(PG_FUNCTION_ARGS)
{
TSVector ts = PG_GETARG_TSVECTOR(0);
ArrayType *a;
Datum *words;
int i;
WordEntry *wptr = ARRPTR(ts);
words = palloc( sizeof(Datum) * (ts->size+1) );
for(i=0; i<ts->size; i++)
{
text *t = palloc(VARHDRSZ + wptr->len);
SET_VARSIZE(t, VARHDRSZ + wptr->len);
memcpy( VARDATA(t), STRPTR(ts) + wptr->pos, wptr->len);
words[i] = PointerGetDatum(t);
wptr++;
}
a = construct_array( words, ts->size,
TEXTOID, -1, false, 'i' );
PG_FREE_IF_COPY(ts, 0);
PG_RETURN_ARRAYTYPE_P(a);
}
示例9: hstore_akeys
Datum
hstore_akeys(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
Datum *d;
ArrayType *a;
HEntry *entries = ARRPTR(hs);
char *base = STRPTR(hs);
int count = HS_COUNT(hs);
int i;
if (count == 0)
{
a = construct_empty_array(TEXTOID);
PG_RETURN_POINTER(a);
}
d = (Datum *) palloc(sizeof(Datum) * count);
for (i = 0; i < count; ++i)
{
text *item = cstring_to_text_with_len(HS_KEY(entries, base, i),
HS_KEYLEN(entries, i));
d[i] = PointerGetDatum(item);
}
a = construct_array(d, count,
TEXTOID, -1, false, 'i');
PG_RETURN_POINTER(a);
}
示例10: build_array
static Datum
build_array(element_set_t * eset, Oid element_type)
{
Datum * array_of_datums;
int i;
int16 typlen;
bool typbyval;
char typalign;
/* do the compaction */
compact_set(eset, false);
#if DEBUG_PROFILE
print_set_stats(eset);
#endif
/* get detailed type information on the element type */
get_typlenbyvalalign(element_type, &typlen, &typbyval, &typalign);
/* Copy data from compact array to array of Datums
* A bit suboptimal way, spends excessive memory
*/
array_of_datums = palloc0(eset->nsorted * sizeof(Datum));
for (i = 0; i < eset->nsorted; i++)
memcpy(array_of_datums + i, eset->data + (eset->item_size * i), eset->item_size);
/* build and return the array */
PG_RETURN_DATUM(PointerGetDatum(construct_array(
array_of_datums, eset->nsorted, element_type, typlen, typbyval, typalign
)));
}
示例11: float4_accum
Datum
float4_accum(PG_FUNCTION_ARGS)
{
ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0);
float4 newval4 = PG_GETARG_FLOAT4(1);
float8 *transvalues;
float8 N,
sumX,
sumX2,
newval;
Datum transdatums[3];
ArrayType *result;
transvalues = check_float8_array(transarray, "float4_accum");
N = transvalues[0];
sumX = transvalues[1];
sumX2 = transvalues[2];
/* Do arithmetic in float8 for best accuracy */
newval = newval4;
N += 1.0;
sumX += newval;
sumX2 += newval * newval;
transdatums[0] = Float8GetDatumFast(N);
transdatums[1] = Float8GetDatumFast(sumX);
transdatums[2] = Float8GetDatumFast(sumX2);
result = construct_array(transdatums, 3,
FLOAT8OID,
sizeof(float8), false /* float8 byval */ , 'd');
PG_RETURN_ARRAYTYPE_P(result);
}
示例12: WeightedNoReplacement
Datum WeightedNoReplacement(PG_FUNCTION_ARGS) {
int value1 = PG_GETARG_INT32(0);
int value2 = PG_GETARG_INT32(1);
int64 *result = (int64*)palloc(sizeof(int64)*value1);
int32 i = 0;
int32 k = 0;
ArrayType *pgarray;
float to_select = value1;
for(;i < value2; i++){
if(rand()%100 < (to_select/(value2 - i))*100){
result[k] = i+1;
k++;
}
if(to_select == 0)
break;
}
pgarray = construct_array((Datum *)result,
value1, INT8OID,
sizeof(int64),true,'d');
PG_RETURN_ARRAYTYPE_P(pgarray);
}
示例13: rotation3d_explode
Datum rotation3d_explode(PG_FUNCTION_ARGS)
{
Rotation3D * rotation3d = (Rotation3D*)PG_GETARG_POINTER(0);
ArrayType * result;
Datum * result_data;
result_data = (Datum*)palloc(sizeof(float8)*9);
if (!result_data)
{
PG_RETURN_NULL();
}
result_data[0] = Float8GetDatum(rotation3d->r11);
result_data[1] = Float8GetDatum(rotation3d->r12);
result_data[2] = Float8GetDatum(rotation3d->r13);
result_data[3] = Float8GetDatum(rotation3d->r21);
result_data[4] = Float8GetDatum(rotation3d->r22);
result_data[5] = Float8GetDatum(rotation3d->r23);
result_data[6] = Float8GetDatum(rotation3d->r31);
result_data[7] = Float8GetDatum(rotation3d->r32);
result_data[8] = Float8GetDatum(rotation3d->r33);
result = construct_array(result_data, 9, FLOAT8OID, sizeof(float8), true, 'd');
pfree(result_data);
PG_RETURN_ARRAYTYPE_P(result);
}
示例14: plr_array_create
/*
* actually does the work for array(), and array_accum() if it is given a null
* input array.
*
* numelems and elem_start allow the function to be shared given the differing
* arguments accepted by array() and array_accum(). With array(), all function
* arguments are used for array construction -- therefore elem_start is 0 and
* numelems is the number of function arguments. With array_accum(), we are
* always initializing the array with a single element given to us as argument
* number 1 (i.e. the second argument).
*
*/
static ArrayType *
plr_array_create(FunctionCallInfo fcinfo, int numelems, int elem_start)
{
Oid funcid = fcinfo->flinfo->fn_oid;
Datum *dvalues = (Datum *) palloc(numelems * sizeof(Datum));
int16 typlen;
bool typbyval;
Oid typinput;
Oid element_type;
char typalign;
int i;
HeapTuple tp;
Oid functypeid;
Oid *funcargtypes;
ArrayType *result;
if (numelems == 0)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("at least one value required to construct an array")));
/*
* Get the type metadata for the array return type and its elements
*/
tp = SearchSysCache(PROCOID,
ObjectIdGetDatum(funcid),
0, 0, 0);
if (!HeapTupleIsValid(tp))
/* internal error */
elog(ERROR, "function OID %u does not exist", funcid);
functypeid = ((Form_pg_proc) GETSTRUCT(tp))->prorettype;
getTypeInputInfo(functypeid, &typinput, &element_type);
get_typlenbyvalalign(element_type, &typlen, &typbyval, &typalign);
funcargtypes = FUNCARGTYPES(tp);
/*
* the first function argument(s) may not be one of our array elements,
* but the caller is responsible to ensure we get nothing but array
* elements once they start coming
*/
for (i = elem_start; i < elem_start + numelems; i++)
if (funcargtypes[i] != element_type)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("argument %d datatype not " \
"compatible with return data type", i + 1)));
ReleaseSysCache(tp);
for (i = 0; i < numelems; i++)
dvalues[i] = PG_GETARG_DATUM(elem_start + i);
result = construct_array(dvalues, numelems, element_type,
typlen, typbyval, typalign);
return result;
}
示例15: rep_aggr_class_count_ffunc
/*
* The final function for aggregating the class counts for REP. It takes the class
* count array produced by the sfunc and produces a two-element array. The first
* element is the ID of the class that has the maximum number of cases represented by
* the root node of the subtree being processed. The second element is the number of
* reduced misclassified cases if the leave nodes of the subtree are pruned.
*
* Parameters:
* class_count_data: The array containing all the information for the
* calculation of Reduced-Error pruning.
* Return:
* A two element array.
*/
Datum rep_aggr_class_count_ffunc(PG_FUNCTION_ARGS)
{
ArrayType *class_count_array = PG_GETARG_ARRAYTYPE_P(0);
int array_dim = ARR_NDIM(class_count_array);
check_error_value
(
array_dim == 1,
"invalid array dimension: %d. The dimension of class count array must be equal to 1",
array_dim
);
int *p_array_dim = ARR_DIMS(class_count_array);
int array_length = ArrayGetNItems(array_dim,p_array_dim);
int64 *class_count_data = (int64 *)ARR_DATA_PTR(class_count_array);
int64 *result = palloc(sizeof(int64)*2);
check_error
(
result,
"memory allocation failure"
);
int64 max = class_count_data[1];
int64 sum = max;
int maxid = 1;
for(int i = 2; i < array_length; ++i)
{
if(max < class_count_data[i])
{
max = class_count_data[i];
maxid = i;
}
sum += class_count_data[i];
}
/* maxid is the id of the class, which has the most cases */
result[0] = maxid;
/*
* (sum - max) is the number of mis-classified cases represented by
* the root node of the subtree being processed
* class_count_data[0] the total number of mis-classified cases
*/
result[1] = class_count_data[0] - (sum - max);
ArrayType* result_array =
construct_array(
(Datum *)result,
2,
INT8OID,
sizeof(int64),
true,
'd'
);
PG_RETURN_ARRAYTYPE_P(result_array);
}