Find pointer to the last element contained in the specified range. * Returns NULL when no element is contained in the range. */
| 881 | /* Find pointer to the last element contained in the specified range. |
| 882 | * Returns NULL when no element is contained in the range. */ |
| 883 | unsigned char *zzlLastInRange(unsigned char *zl, zrangespec *range) { |
| 884 | unsigned char *eptr = ziplistIndex(zl,-2), *sptr; |
| 885 | double score; |
| 886 | |
| 887 | /* If everything is out of range, return early. */ |
| 888 | if (!zzlIsInRange(zl,range)) return NULL; |
| 889 | |
| 890 | while (eptr != NULL) { |
| 891 | sptr = ziplistNext(zl,eptr); |
| 892 | serverAssert(sptr != NULL); |
| 893 | |
| 894 | score = zzlGetScore(sptr); |
| 895 | if (zslValueLteMax(score,range)) { |
| 896 | /* Check if score >= min. */ |
| 897 | if (zslValueGteMin(score,range)) |
| 898 | return eptr; |
| 899 | return NULL; |
| 900 | } |
| 901 | |
| 902 | /* Move to previous element by moving to the score of previous element. |
| 903 | * When this returns NULL, we know there also is no element. */ |
| 904 | sptr = ziplistPrev(zl,eptr); |
| 905 | if (sptr != NULL) |
| 906 | serverAssert((eptr = ziplistPrev(zl,sptr)) != NULL); |
| 907 | else |
| 908 | eptr = NULL; |
| 909 | } |
| 910 | |
| 911 | return NULL; |
| 912 | } |
| 913 | |
| 914 | int zzlLexValueGteMin(unsigned char *p, zlexrangespec *spec) { |
| 915 | sds value = ziplistGetObject(p); |
no test coverage detected