Returns if there is a part of the zset is in range. Should only be used * internally by zzlFirstInRange and zzlLastInRange. */
| 827 | /* Returns if there is a part of the zset is in range. Should only be used |
| 828 | * internally by zzlFirstInRange and zzlLastInRange. */ |
| 829 | int zzlIsInRange(unsigned char *zl, zrangespec *range) { |
| 830 | unsigned char *p; |
| 831 | double score; |
| 832 | |
| 833 | /* Test for ranges that will always be empty. */ |
| 834 | if (range->min > range->max || |
| 835 | (range->min == range->max && (range->minex || range->maxex))) |
| 836 | return 0; |
| 837 | |
| 838 | p = ziplistIndex(zl,-1); /* Last score. */ |
| 839 | if (p == NULL) return 0; /* Empty sorted set */ |
| 840 | score = zzlGetScore(p); |
| 841 | if (!zslValueGteMin(score,range)) |
| 842 | return 0; |
| 843 | |
| 844 | p = ziplistIndex(zl,1); /* First score. */ |
| 845 | serverAssert(p != NULL); |
| 846 | score = zzlGetScore(p); |
| 847 | if (!zslValueLteMax(score,range)) |
| 848 | return 0; |
| 849 | |
| 850 | return 1; |
| 851 | } |
| 852 | |
| 853 | /* Find pointer to the first element contained in the specified range. |
| 854 | * Returns NULL when no element is contained in the range. */ |
no test coverage detected