* array_create_iterator --- set up to iterate through an array * * If slice_ndim is zero, we will iterate element-by-element; the returned * datums are of the array's element type. * * If slice_ndim is 1..ARR_NDIM(arr), we will iterate by slices: the * returned datums are of the same array type as 'arr', but of size * equal to the rightmost N dimensions of 'arr'. * * The passed-in array m
| 4484 | * The passed-in array must remain valid for the lifetime of the iterator. |
| 4485 | */ |
| 4486 | ArrayIterator |
| 4487 | array_create_iterator(ArrayType *arr, int slice_ndim, ArrayMetaState *mstate) |
| 4488 | { |
| 4489 | ArrayIterator iterator = palloc0(sizeof(ArrayIteratorData)); |
| 4490 | |
| 4491 | /* |
| 4492 | * Sanity-check inputs --- caller should have got this right already |
| 4493 | */ |
| 4494 | Assert(PointerIsValid(arr)); |
| 4495 | if (slice_ndim < 0 || slice_ndim > ARR_NDIM(arr)) |
| 4496 | elog(ERROR, "invalid arguments to array_create_iterator"); |
| 4497 | |
| 4498 | /* |
| 4499 | * Remember basic info about the array and its element type |
| 4500 | */ |
| 4501 | iterator->arr = arr; |
| 4502 | iterator->nullbitmap = ARR_NULLBITMAP(arr); |
| 4503 | iterator->nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr)); |
| 4504 | |
| 4505 | if (mstate != NULL) |
| 4506 | { |
| 4507 | Assert(mstate->element_type == ARR_ELEMTYPE(arr)); |
| 4508 | |
| 4509 | iterator->typlen = mstate->typlen; |
| 4510 | iterator->typbyval = mstate->typbyval; |
| 4511 | iterator->typalign = mstate->typalign; |
| 4512 | } |
| 4513 | else |
| 4514 | get_typlenbyvalalign(ARR_ELEMTYPE(arr), |
| 4515 | &iterator->typlen, |
| 4516 | &iterator->typbyval, |
| 4517 | &iterator->typalign); |
| 4518 | |
| 4519 | /* |
| 4520 | * Remember the slicing parameters. |
| 4521 | */ |
| 4522 | iterator->slice_ndim = slice_ndim; |
| 4523 | |
| 4524 | if (slice_ndim > 0) |
| 4525 | { |
| 4526 | /* |
| 4527 | * Get pointers into the array's dims and lbound arrays to represent |
| 4528 | * the dims/lbound arrays of a slice. These are the same as the |
| 4529 | * rightmost N dimensions of the array. |
| 4530 | */ |
| 4531 | iterator->slice_dims = ARR_DIMS(arr) + ARR_NDIM(arr) - slice_ndim; |
| 4532 | iterator->slice_lbound = ARR_LBOUND(arr) + ARR_NDIM(arr) - slice_ndim; |
| 4533 | |
| 4534 | /* |
| 4535 | * Compute number of elements in a slice. |
| 4536 | */ |
| 4537 | iterator->slice_len = ArrayGetNItems(slice_ndim, |
| 4538 | iterator->slice_dims); |
| 4539 | |
| 4540 | /* |
| 4541 | * Create workspace for building sub-arrays. |
| 4542 | */ |
| 4543 | iterator->slice_values = (Datum *) |
no test coverage detected