* @param sdata The SparseData to be projected on * @param idx The index to be projected * @return The element of a SparseData at location idx. */
| 1569 | * @return The element of a SparseData at location idx. |
| 1570 | */ |
| 1571 | double sd_proj(SparseData sdata, int idx) { |
| 1572 | char * ix = sdata->index->data; |
| 1573 | double * vals = (double *)sdata->vals->data; |
| 1574 | int read, i; |
| 1575 | |
| 1576 | /* error checking */ |
| 1577 | if (0 >= idx || idx > sdata->total_value_count) |
| 1578 | ereport(ERROR, |
| 1579 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 1580 | errmsg("Index out of bounds."))); |
| 1581 | |
| 1582 | /* find desired block; as is normal in SQL, we start counting from one */ |
| 1583 | read = compword_to_int8(ix); |
| 1584 | i = 0; |
| 1585 | while (read < idx) { |
| 1586 | ix += int8compstoragesize(ix); |
| 1587 | read += compword_to_int8(ix); |
| 1588 | i++; |
| 1589 | } |
| 1590 | return vals[i]; |
| 1591 | } |
| 1592 | |
| 1593 | /** |
| 1594 | * @param sdata The SparseData from which to extract a subarray |
no test coverage detected