Insert (element,score) pair in ziplist. This function assumes the element is * not yet present in the list. */
| 1057 | /* Insert (element,score) pair in ziplist. This function assumes the element is |
| 1058 | * not yet present in the list. */ |
| 1059 | unsigned char *zzlInsert(unsigned char *zl, sds ele, double score) { |
| 1060 | unsigned char *eptr = ziplistIndex(zl,0), *sptr; |
| 1061 | double s; |
| 1062 | |
| 1063 | while (eptr != NULL) { |
| 1064 | sptr = ziplistNext(zl,eptr); |
| 1065 | serverAssert(sptr != NULL); |
| 1066 | s = zzlGetScore(sptr); |
| 1067 | |
| 1068 | if (s > score) { |
| 1069 | /* First element with score larger than score for element to be |
| 1070 | * inserted. This means we should take its spot in the list to |
| 1071 | * maintain ordering. */ |
| 1072 | zl = zzlInsertAt(zl,eptr,ele,score); |
| 1073 | break; |
| 1074 | } else if (s == score) { |
| 1075 | /* Ensure lexicographical ordering for elements. */ |
| 1076 | if (zzlCompareElements(eptr,(unsigned char*)ele,sdslen(ele)) > 0) { |
| 1077 | zl = zzlInsertAt(zl,eptr,ele,score); |
| 1078 | break; |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | /* Move to next element. */ |
| 1083 | eptr = ziplistNext(zl,sptr); |
| 1084 | } |
| 1085 | |
| 1086 | /* Push on tail of list when it was not yet inserted. */ |
| 1087 | if (eptr == NULL) |
| 1088 | zl = zzlInsertAt(zl,NULL,ele,score); |
| 1089 | return zl; |
| 1090 | } |
| 1091 | |
| 1092 | unsigned char *zzlDeleteRangeByScore(unsigned char *zl, zrangespec *range, unsigned long *deleted) { |
| 1093 | unsigned char *eptr, *sptr; |
no test coverage detected