Compare two SparseData, and return true if the left one is greater. * We can't assume that two SparseData are in canonical form. * * The algorithm is simple: we traverse the left SparseData element by * element, and for each such element x, we traverse all the elements of * the right SparseData that overlaps with x and check that they are equal. * * Note: This function only works on SparseD
| 712 | * Note: This function only works on SparseData of float8s at present. |
| 713 | */ |
| 714 | bool sparsedata_gt(SparseData left, SparseData right) |
| 715 | { |
| 716 | char * ix = left->index->data; |
| 717 | double * vals = (double *)left->vals->data; |
| 718 | |
| 719 | char * rix = right->index->data; |
| 720 | double * rvals = (double *)right->vals->data; |
| 721 | |
| 722 | int read = 0, rread = 0; |
| 723 | int rvid = 0; |
| 724 | int rrun_length, i; |
| 725 | |
| 726 | for (i=0; i<left->unique_value_count; i++,ix+=int8compstoragesize(ix)) { |
| 727 | read += compword_to_int8(ix); |
| 728 | |
| 729 | while (true) { |
| 730 | /* |
| 731 | * Note: IEEE754 specifies that NaN should not compare equal to |
| 732 | * any other floating-point value (including NaN). In order to |
| 733 | * allow floating-point values to be sorted and used in tree-based |
| 734 | * indexes, PostgreSQL treats NaN values as equal, and greater |
| 735 | * than all non-NaN values. NULLs are represented as NVPs here. |
| 736 | * |
| 737 | * NULL (NVP) > NaN > INF |
| 738 | */ |
| 739 | if (!IS_NVP(vals[i]) || !IS_NVP(rvals[rvid])) { |
| 740 | if (IS_NVP(vals[i])) { return true; } |
| 741 | else if (IS_NVP(rvals[rvid])) { return false; } |
| 742 | else if (!isnan(vals[i]) || !isnan(rvals[rvid])) { |
| 743 | if (isnan(vals[i])) { return true; } |
| 744 | else if (isnan(rvals[rvid])) { return false; } |
| 745 | else if (vals[i] > rvals[rvid]) { return true; } |
| 746 | else if (vals[i] < rvals[rvid]) { return false; } |
| 747 | } |
| 748 | // else NaN == NaN is true |
| 749 | } |
| 750 | // else NVP == NVP is true |
| 751 | |
| 752 | /* |
| 753 | * We never move the right element pointer beyond |
| 754 | * the current left element |
| 755 | */ |
| 756 | rrun_length = compword_to_int8(rix); |
| 757 | if (rread + rrun_length > read) break; |
| 758 | |
| 759 | /* |
| 760 | * Increase counters if there are more elements in |
| 761 | * the right SparseData that overlaps with current |
| 762 | * left element |
| 763 | */ |
| 764 | rread += rrun_length; |
| 765 | if (rvid < right->unique_value_count) { |
| 766 | rix += int8compstoragesize(rix); |
| 767 | rvid++; |
| 768 | } |
| 769 | if (rvid == right->unique_value_count) { |
| 770 | Assert(left->total_value_count >= right->total_value_count); |
| 771 | if (left->total_value_count == right->total_value_count) { |
no test coverage detected