* @param array The array of elements to be converted to a SparseData * @param width The size of the elements in array * @param type_of_data The object ID of the elements in array * @param count The size of array * @return A SparseData representation of an input array */
| 1333 | * @return A SparseData representation of an input array |
| 1334 | */ |
| 1335 | SparseData arr_to_sdata(char *array, size_t width, Oid type_of_data, int count){ |
| 1336 | char *run_val=array; |
| 1337 | int64 run_len=1; |
| 1338 | SparseData sdata = makeSparseData(); |
| 1339 | |
| 1340 | sdata->type_of_data=type_of_data; |
| 1341 | |
| 1342 | for (int i=1; i<count; i++) { |
| 1343 | char *curr_val=array+ (i*size_of_type(type_of_data)); |
| 1344 | |
| 1345 | /* |
| 1346 | * Note that special double values like denormalized numbers and exceptions |
| 1347 | * like NaN are treated like any other value - if there are duplicates, the |
| 1348 | * value of the special number is preserved and they are counted. |
| 1349 | */ |
| 1350 | if (memcmp(curr_val,run_val,width)) |
| 1351 | { /*run is interrupted, initiate new run */ |
| 1352 | /* package up the finished run */ |
| 1353 | add_run_to_sdata(run_val,run_len,width,sdata); |
| 1354 | /* mark beginning of new run */ |
| 1355 | run_val=curr_val; |
| 1356 | run_len=1; |
| 1357 | } else |
| 1358 | { /* we're still in the same run */ |
| 1359 | run_len++; |
| 1360 | } |
| 1361 | } |
| 1362 | add_run_to_sdata(run_val, run_len, width, sdata); /* package up the last run */ |
| 1363 | |
| 1364 | /* Add the final tallies */ |
| 1365 | sdata->unique_value_count = sdata->vals->len/width; |
| 1366 | sdata->total_value_count = count; |
| 1367 | |
| 1368 | return sdata; |
| 1369 | } |
| 1370 | |
| 1371 | int compar(const void *i, const void *j){ |
| 1372 | return (int)((int64*)array_pos_ref)[*(int*)i] - ((int64*)array_pos_ref)[*(int*)j]; |
no test coverage detected