Find pointer to the last element contained in the specified lex range. * Returns NULL when no element is contained in the range. */
| 976 | /* Find pointer to the last element contained in the specified lex range. |
| 977 | * Returns NULL when no element is contained in the range. */ |
| 978 | unsigned char *zzlLastInLexRange(unsigned char *zl, zlexrangespec *range) { |
| 979 | unsigned char *eptr = ziplistIndex(zl,-2), *sptr; |
| 980 | |
| 981 | /* If everything is out of range, return early. */ |
| 982 | if (!zzlIsInLexRange(zl,range)) return NULL; |
| 983 | |
| 984 | while (eptr != NULL) { |
| 985 | if (zzlLexValueLteMax(eptr,range)) { |
| 986 | /* Check if score >= min. */ |
| 987 | if (zzlLexValueGteMin(eptr,range)) |
| 988 | return eptr; |
| 989 | return NULL; |
| 990 | } |
| 991 | |
| 992 | /* Move to previous element by moving to the score of previous element. |
| 993 | * When this returns NULL, we know there also is no element. */ |
| 994 | sptr = ziplistPrev(zl,eptr); |
| 995 | if (sptr != NULL) |
| 996 | serverAssert((eptr = ziplistPrev(zl,sptr)) != NULL); |
| 997 | else |
| 998 | eptr = NULL; |
| 999 | } |
| 1000 | |
| 1001 | return NULL; |
| 1002 | } |
| 1003 | |
| 1004 | unsigned char *zzlFind(unsigned char *zl, sds ele, double *score) { |
| 1005 | unsigned char *eptr = ziplistIndex(zl,0), *sptr; |
no test coverage detected