MCPcopy Create free account
hub / github.com/apache/madlib / svec_change

Function svec_change

methods/svec_util/src/pg_gp/svec_util.c:312–350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

310Datum svec_change(PG_FUNCTION_ARGS);
311PG_FUNCTION_INFO_V1(svec_change);
312Datum svec_change(PG_FUNCTION_ARGS)
313{
314 SvecType * in = PG_GETARG_SVECTYPE_P(0);
315 int idx = PG_GETARG_INT32(1);
316 SvecType * changed = PG_GETARG_SVECTYPE_P(2);
317 SparseData indata = sdata_from_svec(in);
318 SparseData middle = sdata_from_svec(changed);
319 int inlen = indata->total_value_count;
320 int midlen = middle->total_value_count;
321 SparseData head = NULL, tail = NULL, ret = NULL;
322
323 Assert((IS_SCALAR(changed) && midlen == 1) ||
324 (midlen == changed->dimension));
325
326 if (idx < 1 || idx > inlen)
327 ereport(ERROR,
328 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
329 errmsg("Invalid start index")));
330
331 if (idx+midlen-1 > inlen)
332 ereport(ERROR,
333 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
334 errmsg("Change vector is too long")));
335
336 if (idx >= 2) head = subarr(indata, 1, idx-1);
337 if (idx + midlen <= inlen) tail = subarr(indata,idx + midlen, inlen);
338
339 if (head == NULL && tail == NULL)
340 ret = makeSparseDataCopy(middle);
341 else if (head == NULL)
342 ret = concat(middle, tail);
343 else if (tail == NULL)
344 ret = concat(head, middle);
345 else {
346 ret = concat(head, middle);
347 ret = concat(ret, tail);
348 }
349 PG_RETURN_SVECTYPE_P(svec_from_sparsedata(ret,true));
350}
351
352/**
353 * svec_eq - returns the equality of two svecs if their

Callers

nothing calls this directly

Calls 5

sdata_from_svecFunction · 0.85
subarrFunction · 0.85
makeSparseDataCopyFunction · 0.85
concatFunction · 0.85
svec_from_sparsedataFunction · 0.85

Tested by

no test coverage detected