| 1032 | } |
| 1033 | |
| 1034 | unsigned char *zzlInsertAt(unsigned char *zl, unsigned char *eptr, sds ele, double score) { |
| 1035 | unsigned char *sptr; |
| 1036 | char scorebuf[128]; |
| 1037 | int scorelen; |
| 1038 | size_t offset; |
| 1039 | |
| 1040 | scorelen = d2string(scorebuf,sizeof(scorebuf),score); |
| 1041 | if (eptr == NULL) { |
| 1042 | zl = ziplistPush(zl,(unsigned char*)ele,sdslen(ele),ZIPLIST_TAIL); |
| 1043 | zl = ziplistPush(zl,(unsigned char*)scorebuf,scorelen,ZIPLIST_TAIL); |
| 1044 | } else { |
| 1045 | /* Keep offset relative to zl, as it might be re-allocated. */ |
| 1046 | offset = eptr-zl; |
| 1047 | zl = ziplistInsert(zl,eptr,(unsigned char*)ele,sdslen(ele)); |
| 1048 | eptr = zl+offset; |
| 1049 | |
| 1050 | /* Insert score after the element. */ |
| 1051 | serverAssert((sptr = ziplistNext(zl,eptr)) != NULL); |
| 1052 | zl = ziplistInsert(zl,sptr,(unsigned char*)scorebuf,scorelen); |
| 1053 | } |
| 1054 | return zl; |
| 1055 | } |
| 1056 | |
| 1057 | /* Insert (element,score) pair in ziplist. This function assumes the element is |
| 1058 | * not yet present in the list. */ |
no test coverage detected