compareSeriesMapKey compares two SeriesMapKey values deterministically. Returns -1 if a < b, 0 if a == b, 1 if a > b
(a, b SeriesMapKey)
| 11 | // compareSeriesMapKey compares two SeriesMapKey values deterministically. |
| 12 | // Returns -1 if a < b, 0 if a == b, 1 if a > b |
| 13 | func compareSeriesMapKey(a, b SeriesMapKey) int { |
| 14 | for i := range a { |
| 15 | // labels should be in the same order so we should really only have to compare value strings here. |
| 16 | // doing the resut of comparisons for safety. |
| 17 | if cmp := strings.Compare(a[i].Value.str, b[i].Value.str); cmp != 0 { |
| 18 | return cmp * -1 // reverse the order b/c we want topk to return alphabetically earlier first |
| 19 | } |
| 20 | if cmp := strings.Compare(a[i].Name, b[i].Name); cmp != 0 { |
| 21 | return cmp * -1 |
| 22 | } |
| 23 | if a[i].Value.typ != b[i].Value.typ { |
| 24 | if a[i].Value.typ < b[i].Value.typ { |
| 25 | return -1 |
| 26 | } |
| 27 | return 1 |
| 28 | } |
| 29 | if a[i].Value.code != b[i].Value.code { |
| 30 | if a[i].Value.code < b[i].Value.code { |
| 31 | return -1 |
| 32 | } |
| 33 | return 1 |
| 34 | } |
| 35 | } |
| 36 | return 0 |
| 37 | } |
| 38 | |
| 39 | // dataPointGreaterThan returns true if the new value should replace the smallest in a topk heap. |
| 40 | // This happens when the new value is greater, or equal but alphabetically earlier. |