您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ ziplistIndex函数代码示例

51自学网 2021-06-03 12:00:13
  C++
这篇教程C++ ziplistIndex函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中ziplistIndex函数的典型用法代码示例。如果您正苦于以下问题:C++ ziplistIndex函数的具体用法?C++ ziplistIndex怎么用?C++ ziplistIndex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了ziplistIndex函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: verify

void verify(unsigned char *zl, zlentry *e) {    int i;    int len = ziplistLen(zl);    zlentry _e;    for (i = 0; i < len; i++) {        memset(&e[i], 0, sizeof(zlentry));        e[i] = zipEntry(ziplistIndex(zl, i));        memset(&_e, 0, sizeof(zlentry));        _e = zipEntry(ziplistIndex(zl, -len+i));        assert(memcmp(&e[i], &_e, sizeof(zlentry)) == 0);    }}
开发者ID:royalwang,项目名称:sundial,代码行数:15,


示例2: lindexCommand

void lindexCommand(redisClient *c) {    robj *o = lookupKeyReadOrReply(c,c->argv[1],shared.nullbulk);    if (o == NULL || checkType(c,o,REDIS_LIST)) return;    int index = atoi(c->argv[2]->ptr);    robj *value = NULL;    if (o->encoding == REDIS_ENCODING_ZIPLIST) {        unsigned char *p;        unsigned char *vstr;        unsigned int vlen;        long long vlong;        p = ziplistIndex(o->ptr,index);        if (ziplistGet(p,&vstr,&vlen,&vlong)) {            if (vstr) {                value = createStringObject((char*)vstr,vlen);            } else {                value = createStringObjectFromLongLong(vlong);            }            addReplyBulk(c,value);            decrRefCount(value);        } else {            addReply(c,shared.nullbulk);        }    } else if (o->encoding == REDIS_ENCODING_LINKEDLIST) {        listNode *ln = listIndex(o->ptr,index);        if (ln != NULL) {            value = listNodeValue(ln);            addReplyBulk(c,value);        } else {            addReply(c,shared.nullbulk);        }    } else {        redisPanic("Unknown list encoding");    }}
开发者ID:brunobnb,项目名称:brtGHost,代码行数:35,


示例3: hashTypeGetFromZiplist

/* Get the value from a ziplist encoded hash, identified by field. * Returns -1 when the field cannot be found. */int hashTypeGetFromZiplist(robj *o, robj *field,                           unsigned char **vstr,                           unsigned int *vlen,                           long long *vll){    unsigned char *zl, *fptr = NULL, *vptr = NULL;    int ret;    logicErrorExpr(o->encoding == REDIS_ENCODING_ZIPLIST, "Never happend");    field = getDecodedObject(field);    zl = o->ptr;    fptr = ziplistIndex(zl, ZIPLIST_HEAD);    if (fptr != NULL) {        fptr = ziplistFind(fptr, field->ptr, sdslen(field->ptr), 1);        if (fptr != NULL) {            /* Grab pointer to the value (fptr points to the field) */            vptr = ziplistNext(zl, fptr);            logicErrorExpr(vptr != NULL, "Never happend");        }    }    decrRefCount(field);    if (vptr != NULL) {        ret = ziplistGet(vptr, vstr, vlen, vll);        logicErrorExpr(ret, "Never happend");        return 0;    }    return -1;}
开发者ID:jianzi123,项目名称:my_libucmq,代码行数:35,


示例4: hashTypeNext

/* Move to the next entry in the hash. Return REDIS_OK when the next entry * could be found and REDIS_ERR when the iterator reaches the end. */int hashTypeNext(hashTypeIterator *hi) {    if (hi->encoding == REDIS_ENCODING_ZIPLIST) {        unsigned char *zl;        unsigned char *fptr, *vptr;        zl = hi->subject->ptr;        fptr = hi->fptr;        vptr = hi->vptr;        if (fptr == NULL) {            /* Initialize cursor */                logicErrorExpr(vptr == NULL, "Never happend");            fptr = ziplistIndex(zl, 0);        } else {            /* Advance cursor */                logicErrorExpr(vptr != NULL, "Never happend");            fptr = ziplistNext(zl, vptr);        }        if (fptr == NULL) return REDIS_ERR;        /* Grab pointer to the value (fptr points to the field) */        vptr = ziplistNext(zl, fptr);        logicErrorExpr(vptr != NULL, "Never happend");        /* fptr, vptr now point to the first or next pair */        hi->fptr = fptr;        hi->vptr = vptr;    } else if (hi->encoding == REDIS_ENCODING_HT) {        if ((hi->de = dictNext(hi->di)) == NULL) return REDIS_ERR;    } else {        logicError("Unknown hash encoding");    }    return REDIS_OK;}
开发者ID:jianzi123,项目名称:my_libucmq,代码行数:36,


示例5: zmalloc

/* Initialize an iterator at the specified index. */listTypeIterator *listTypeInitIterator(robj *subject, PORT_LONG index, unsigned char direction) {    listTypeIterator *li = zmalloc(sizeof(listTypeIterator));    li->subject = subject;    li->encoding = subject->encoding;    li->direction = direction;    if (li->encoding == REDIS_ENCODING_ZIPLIST) {        li->zi = ziplistIndex(subject->ptr,(int)index);                         WIN_PORT_FIX /* cast (int) */    } else if (li->encoding == REDIS_ENCODING_LINKEDLIST) {
开发者ID:vizcount,项目名称:work,代码行数:9,


示例6: lrangeCommand

void lrangeCommand(redisClient *c) {    robj *o;    long start, end, llen, rangelen;    if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != REDIS_OK) ||        (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != REDIS_OK)) return;    if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptymultibulk)) == NULL         || checkType(c,o,REDIS_LIST)) return;    llen = listTypeLength(o);    /* convert negative indexes */    if (start < 0) start = llen+start;    if (end < 0) end = llen+end;    if (start < 0) start = 0;    /* Invariant: start >= 0, so this test will be true when end < 0.     * The range is empty when start > end or start >= length. */    if (start > end || start >= llen) {        addReply(c,shared.emptymultibulk);        return;    }    if (end >= llen) end = llen-1;    rangelen = (end-start)+1;    /* Return the result in form of a multi-bulk reply */    addReplyMultiBulkLen(c,rangelen);    if (o->encoding == REDIS_ENCODING_ZIPLIST) {        unsigned char *p = ziplistIndex(o->ptr,start);        unsigned char *vstr;        unsigned int vlen;        long long vlong;        while(rangelen--) {            ziplistGet(p,&vstr,&vlen,&vlong);            if (vstr) {                addReplyBulkCBuffer(c,vstr,vlen);            } else {                addReplyBulkLongLong(c,vlong);            }            p = ziplistNext(o->ptr,p);        }    } else if (o->encoding == REDIS_ENCODING_LINKEDLIST) {        listNode *ln;        /* If we are nearest to the end of the list, reach the element         * starting from tail and going backward, as it is faster. */        if (start > llen/2) start -= llen;        ln = listIndex(o->ptr,start);        while(rangelen--) {            addReplyBulk(c,ln->value);            ln = ln->next;        }    } else {        redisPanic("List encoding is not LINKEDLIST nor ZIPLIST!");    }}
开发者ID:CNCBASHER,项目名称:linuxcnc-1,代码行数:58,


示例7: hashTypeSet

/* Add an element, discard the old if the key already exists. * Return 0 on insert and 1 on update. * This function will take care of incrementing the reference count of the * retained fields and value objects. */int hashTypeSet(robj *o, robj *field, robj *value) {    int update = 0;    if (o->encoding == REDIS_ENCODING_ZIPLIST) {        unsigned char *zl, *fptr, *vptr;        field = getDecodedObject(field);        value = getDecodedObject(value);        zl = o->ptr;        fptr = ziplistIndex(zl, ZIPLIST_HEAD);        if (fptr != NULL) {            fptr = ziplistFind(fptr, field->ptr, sdslen(field->ptr), 1);            if (fptr != NULL) {                /* Grab pointer to the value (fptr points to the field) */                vptr = ziplistNext(zl, fptr);                logicErrorExpr(vptr != NULL, "Never happend");                update = 1;                /* Delete value */                zl = ziplistDelete(zl, &vptr);                /* Insert new value */                zl = ziplistInsert(zl, vptr, value->ptr, sdslen(value->ptr));            }        }        if (!update) {            /* Push new field/value pair onto the tail of the ziplist */            zl = ziplistPush(zl, field->ptr, sdslen(field->ptr), ZIPLIST_TAIL);            zl = ziplistPush(zl, value->ptr, sdslen(value->ptr), ZIPLIST_TAIL);        }        o->ptr = zl;        decrRefCount(field);        decrRefCount(value);        /* Check if the ziplist needs to be converted to a hash table */        if (hashTypeLength(o) > server.hash_max_ziplist_entries)            hashTypeConvert(o, REDIS_ENCODING_HT);    } else if (o->encoding == REDIS_ENCODING_HT) {        if (dictReplace(o->ptr, field, value)) { /* Insert */            incrRefCount(field);        } else { /* Update */            update = 1;        }        incrRefCount(value);    } else {        logicError("Unknown hash encoding");    }    return update;}
开发者ID:jianzi123,项目名称:my_libucmq,代码行数:55,


示例8: zmalloc

/* Initialize an iterator at the specified index. */listTypeIterator *listTypeInitIterator(robj *subject, long index, unsigned char direction) {    listTypeIterator *li = zmalloc(sizeof(listTypeIterator));    li->subject = subject;    li->encoding = subject->encoding;    li->direction = direction;    if (li->encoding == REDIS_ENCODING_ZIPLIST) {        li->zi = ziplistIndex(subject->ptr,index);    } else if (li->encoding == REDIS_ENCODING_LINKEDLIST) {        li->ln = listIndex(subject->ptr,index);    } else {        redisPanic("Unknown list encoding");    }    return li;}
开发者ID:CNCBASHER,项目名称:linuxcnc-1,代码行数:15,


示例9: lsetCommand

void lsetCommand(redisClient *c) {	int slotnum = keyHashSlot(c->argv[1]->ptr, sdslen(c->argv[1]->ptr));    robj *o = lookupKeyWriteOrReply(c,c->argv[1],shared.nokeyerr,slotnum);    if (o == NULL || checkType(c,o,REDIS_LIST)) return;    long index;    robj *value = (c->argv[3] = tryObjectEncoding(c->argv[3]));    if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != REDIS_OK))        return;    listTypeTryConversion(o,value);    if (o->encoding == REDIS_ENCODING_ZIPLIST) {        unsigned char *p, *zl = o->ptr;        p = ziplistIndex(zl,index);        if (p == NULL) {            addReply(c,shared.outofrangeerr);        } else {            o->ptr = ziplistDelete(o->ptr,&p);            value = getDecodedObject(value);            o->ptr = ziplistInsert(o->ptr,p,value->ptr,sdslen(value->ptr));            decrRefCount(value);            addReply(c,shared.ok);            signalModifiedKey(c->db,c->argv[1],slotnum);            notifyKeyspaceEvent(REDIS_NOTIFY_LIST,"lset",c->argv[1],c->db->id);            server.dirty++;        }    } else if (o->encoding == REDIS_ENCODING_LINKEDLIST) {        listNode *ln = listIndex(o->ptr,index);        if (ln == NULL) {            addReply(c,shared.outofrangeerr);        } else {            decrRefCount((robj*)listNodeValue(ln));            listNodeValue(ln) = value;            incrRefCount(value);            addReply(c,shared.ok);            signalModifiedKey(c->db,c->argv[1],slotnum);            notifyKeyspaceEvent(REDIS_NOTIFY_LIST,"lset",c->argv[1],c->db->id);            server.dirty++;        }    } else {        redisPanic("Unknown list encoding");    }}
开发者ID:frostyplanet,项目名称:jimdb,代码行数:43,


示例10: hashTypeGetFromZiplist

/* Get the value from a ziplist encoded hash, identified by field. * Returns -1 when the field cannot be found. */int hashTypeGetFromZiplist(robj *o, robj *field,                           unsigned char **vstr,                           unsigned int *vlen,                           PORT_LONGLONG *vll){    unsigned char *zl, *fptr = NULL, *vptr = NULL;    int ret;    redisAssert(o->encoding == REDIS_ENCODING_ZIPLIST);    field = getDecodedObject(field);    zl = o->ptr;    fptr = ziplistIndex(zl, ZIPLIST_HEAD);    if (fptr != NULL) {        fptr = ziplistFind(fptr, field->ptr, (unsigned int)sdslen(field->ptr), 1); WIN_PORT_FIX /* cast (unsigned int) */        if (fptr != NULL) {            /* Grab pointer to the value (fptr points to the field) */            vptr = ziplistNext(zl, fptr);            redisAssert(vptr != NULL);        }    }
开发者ID:mz02005,项目名称:CScript,代码行数:24,


示例11: lsetCommand

void lsetCommand(redisClient *c) {    robj *o = lookupKeyWriteOrReply(c,c->argv[1],shared.nokeyerr);    if (o == NULL || checkType(c,o,REDIS_LIST)) return;    int index = atoi(c->argv[2]->ptr);    robj *value = (c->argv[3] = tryObjectEncoding(c->argv[3]));    listTypeTryConversion(o,value);    if (o->encoding == REDIS_ENCODING_ZIPLIST) {        unsigned char *p, *zl = o->ptr;        p = ziplistIndex(zl,index);        if (p == NULL) {            addReply(c,shared.outofrangeerr);        } else {            o->ptr = ziplistDelete(o->ptr,&p);            value = getDecodedObject(value);            o->ptr = ziplistInsert(o->ptr,p,value->ptr,sdslen(value->ptr));            decrRefCount(value);            addReply(c,shared.ok);            signalModifiedKey(c->db,c->argv[1]);            server.dirty++;        }    } else if (o->encoding == REDIS_ENCODING_LINKEDLIST) {        listNode *ln = listIndex(o->ptr,index);        if (ln == NULL) {            addReply(c,shared.outofrangeerr);        } else {            decrRefCount((robj*)listNodeValue(ln));            listNodeValue(ln) = value;            incrRefCount(value);            addReply(c,shared.ok);            signalModifiedKey(c->db,c->argv[1]);            server.dirty++;        }    } else {        redisPanic("Unknown list encoding");    }}
开发者ID:brunobnb,项目名称:brtGHost,代码行数:37,


示例12: ziplistIndex

robj *listTypePop(robj *subject, int where) {    robj *value = NULL;    if (subject->encoding == REDIS_ENCODING_ZIPLIST) {        unsigned char *p;        unsigned char *vstr;        unsigned int vlen;        long long vlong;        int pos = (where == REDIS_HEAD) ? 0 : -1;        p = ziplistIndex(subject->ptr,pos);        if (ziplistGet(p,&vstr,&vlen,&vlong)) {            if (vstr) {                value = createStringObject((char*)vstr,vlen);            } else {                value = createStringObjectFromLongLong(vlong);            }            /* We only need to delete an element when it exists */            subject->ptr = ziplistDelete(subject->ptr,&p);        }    } else if (subject->encoding == REDIS_ENCODING_LINKEDLIST) {        list *list = subject->ptr;        listNode *ln;        if (where == REDIS_HEAD) {            ln = listFirst(list);        } else {            ln = listLast(list);        }        if (ln != NULL) {            value = listNodeValue(ln);            incrRefCount(value);            listDelNode(list,ln);        }    } else {        redisPanic("Unknown list encoding");    }    return value;}
开发者ID:CNCBASHER,项目名称:linuxcnc-1,代码行数:36,


示例13: ziplistLen

static void *loadZsetZiplistObject(unsigned char* zl, unsigned int *rlen) {    unsigned int i = 0, len;    unsigned char *eptr, *sptr;    unsigned char *vstr;    unsigned int vlen;    int buf_len;    long long vlong;    double score;    char buf[128];    sds ele;    len = ziplistLen (zl);    eptr = ziplistIndex(zl,0);    sptr = ziplistNext(zl,eptr);    if(rdb_version < 2) {        *rlen = len * 2;    } else {        *rlen = len;    }    sds *results = zmalloc(*rlen * sizeof(sds));    while (eptr != NULL) {        score = zzlGetScore(sptr);        ziplistGet(eptr,&vstr,&vlen,&vlong);        if (vstr == NULL)            ele = sdsfromlonglong(vlong);        else            ele = sdsnewlen((char*)vstr,vlen);        results[i] = ele;        buf_len = snprintf(buf, 128, "%f", score);        results[i+1] = sdsnewlen(buf, buf_len);        i += 2;        zzlNext(zl,&eptr,&sptr);    }    return results;}
开发者ID:hilllinux,项目名称:rdbtools,代码行数:36,


示例14: hashTypeDelete

/* Delete an element from a hash. * Return 1 on deleted and 0 on not found. */int hashTypeDelete(robj *o, robj *field) {    int deleted = 0;    if (o->encoding == REDIS_ENCODING_ZIPLIST) {        unsigned char *zl, *fptr;        field = getDecodedObject(field);        zl = o->ptr;        fptr = ziplistIndex(zl, ZIPLIST_HEAD);        if (fptr != NULL) {            fptr = ziplistFind(fptr, field->ptr, sdslen(field->ptr), 1);            if (fptr != NULL) {                zl = ziplistDelete(zl,&fptr);                zl = ziplistDelete(zl,&fptr);                o->ptr = zl;                deleted = 1;            }        }        decrRefCount(field);    } else if (o->encoding == REDIS_ENCODING_HT) {        if (dictDelete((dict*)o->ptr, field) == REDIS_OK) {            deleted = 1;            /* Always check if the dictionary needs a resize after a delete. */            if (htNeedsResize(o->ptr)) dictResize(o->ptr);        }    } else {        logicError("Unknown hash encoding");    }    return deleted;}
开发者ID:jianzi123,项目名称:my_libucmq,代码行数:38,


示例15: pop

void pop(unsigned char *zl, int where) {    unsigned char *p, *vstr;    unsigned int vlen;    long long vlong;    p = ziplistIndex(zl,where == ZIPLIST_HEAD ? 0 : -1);    if (ziplistGet(p,&vstr,&vlen,&vlong)) {        if (where == ZIPLIST_HEAD)            printf("Pop head: ");        else            printf("Pop tail: ");        if (vstr)            if (vlen && fwrite(vstr,vlen,1,stdout) == 0) perror("fwrite");        else            printf("%lld", vlong);        printf("/n");        ziplistDeleteRange(zl,-1,1);    } else {        printf("ERROR: Could not pop/n");        exit(1);    }}
开发者ID:royalwang,项目名称:sundial,代码行数:24,


示例16: rewriteAppendOnlyFile

/* Write a sequence of commands able to fully rebuild the dataset into * "filename". Used both by REWRITEAOF and BGREWRITEAOF. */int rewriteAppendOnlyFile(char *filename) {    dictIterator *di = NULL;    dictEntry *de;    FILE *fp;    char tmpfile[256];    int j;    time_t now = time(NULL);    /* Note that we have to use a different temp name here compared to the     * one used by rewriteAppendOnlyFileBackground() function. */    snprintf(tmpfile,256,"temp-rewriteaof-%d.aof", (int) getpid());    fp = fopen(tmpfile,"w");    if (!fp) {        redisLog(REDIS_WARNING, "Failed rewriting the append only file: %s", strerror(errno));        return REDIS_ERR;    }    for (j = 0; j < server.dbnum; j++) {        char selectcmd[] = "*2/r/n$6/r/nSELECT/r/n";        redisDb *db = server.db+j;        dict *d = db->dict;        if (dictSize(d) == 0) continue;        di = dictGetSafeIterator(d);        if (!di) {            fclose(fp);            return REDIS_ERR;        }        /* SELECT the new DB */        if (fwrite(selectcmd,sizeof(selectcmd)-1,1,fp) == 0) goto werr;        if (fwriteBulkLongLong(fp,j) == 0) goto werr;        /* Iterate this DB writing every entry */        while((de = dictNext(di)) != NULL) {            sds keystr = dictGetEntryKey(de);            robj key, *o;            time_t expiretime;            int swapped;            keystr = dictGetEntryKey(de);            o = dictGetEntryVal(de);            initStaticStringObject(key,keystr);            /* If the value for this key is swapped, load a preview in memory.             * We use a "swapped" flag to remember if we need to free the             * value object instead to just increment the ref count anyway             * in order to avoid copy-on-write of pages if we are forked() */            if (!server.vm_enabled || o->storage == REDIS_VM_MEMORY ||                o->storage == REDIS_VM_SWAPPING) {                swapped = 0;            } else {                o = vmPreviewObject(o);                swapped = 1;            }            expiretime = getExpire(db,&key);            /* Save the key and associated value */            if (o->type == REDIS_STRING) {                /* Emit a SET command */                char cmd[]="*3/r/n$3/r/nSET/r/n";                if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;                /* Key and value */                if (fwriteBulkObject(fp,&key) == 0) goto werr;                if (fwriteBulkObject(fp,o) == 0) goto werr;            } else if (o->type == REDIS_LIST) {                /* Emit the RPUSHes needed to rebuild the list */                char cmd[]="*3/r/n$5/r/nRPUSH/r/n";                if (o->encoding == REDIS_ENCODING_ZIPLIST) {                    unsigned char *zl = o->ptr;                    unsigned char *p = ziplistIndex(zl,0);                    unsigned char *vstr;                    unsigned int vlen;                    long long vlong;                    while(ziplistGet(p,&vstr,&vlen,&vlong)) {                        if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;                        if (fwriteBulkObject(fp,&key) == 0) goto werr;                        if (vstr) {                            if (fwriteBulkString(fp,(char*)vstr,vlen) == 0)                                goto werr;                        } else {                            if (fwriteBulkLongLong(fp,vlong) == 0)                                goto werr;                        }                        p = ziplistNext(zl,p);                    }                } else if (o->encoding == REDIS_ENCODING_LINKEDLIST) {                    list *list = o->ptr;                    listNode *ln;                    listIter li;                    listRewind(list,&li);                    while((ln = listNext(&li))) {                        robj *eleobj = listNodeValue(ln);                        if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;                        if (fwriteBulkObject(fp,&key) == 0) goto werr;                        if (fwriteBulkObject(fp,eleobj) == 0) goto werr;                    }                } else {//.........这里部分代码省略.........
开发者ID:BoTreeConsulting,项目名称:multiple_login,代码行数:101,


示例17: main

int main(int argc, char *argv[]){    unsigned char *zl, *p;    unsigned char *entry;    unsigned int elen;    long long value;    /* If an argument is given, use it as the random seed. */    if (argc == 2)        srand(atoi(argv[1]));    zl = createIntList();    ziplistRepr(zl);    zl = createList();    ziplistRepr(zl);    pop(zl,ZIPLIST_TAIL);    ziplistRepr(zl);    pop(zl,ZIPLIST_HEAD);    ziplistRepr(zl);    pop(zl,ZIPLIST_TAIL);    ziplistRepr(zl);    pop(zl,ZIPLIST_TAIL);    ziplistRepr(zl);    printf("Get element at index 3:/n");    {        zl = createList();        p = ziplistIndex(zl, 3);        if (!ziplistGet(p, &entry, &elen, &value)) {            printf("ERROR: Could not access index 3/n");            return 1;        }        if (entry) {            if (elen && fwrite(entry,elen,1,stdout) == 0) perror("fwrite");            printf("/n");        } else {            printf("%lld/n", value);        }        printf("/n");    }    printf("Get element at index 4 (out of range):/n");    {        zl = createList();        p = ziplistIndex(zl, 4);        if (p == NULL) {            printf("No entry/n");        } else {            printf("ERROR: Out of range index should return NULL, returned offset: %ld/n", p-zl);            return 1;        }        printf("/n");    }    printf("Get element at index -1 (last element):/n");    {        zl = createList();        p = ziplistIndex(zl, -1);        if (!ziplistGet(p, &entry, &elen, &value)) {            printf("ERROR: Could not access index -1/n");            return 1;        }        if (entry) {            if (elen && fwrite(entry,elen,1,stdout) == 0) perror("fwrite");            printf("/n");        } else {            printf("%lld/n", value);        }        printf("/n");    }    printf("Get element at index -4 (first element):/n");    {        zl = createList();        p = ziplistIndex(zl, -4);        if (!ziplistGet(p, &entry, &elen, &value)) {            printf("ERROR: Could not access index -4/n");            return 1;        }        if (entry) {            if (elen && fwrite(entry,elen,1,stdout) == 0) perror("fwrite");            printf("/n");        } else {            printf("%lld/n", value);        }        printf("/n");    }    printf("Get element at index -5 (reverse out of range):/n");    {        zl = createList();        p = ziplistIndex(zl, -5);        if (p == NULL) {            printf("No entry/n");//.........这里部分代码省略.........
开发者ID:royalwang,项目名称:sundial,代码行数:101,


示例18: scanGenericCommand

//.........这里部分代码省略.........        count *= 2; /* We return key / value for this type. */    } else if (o->type == OBJ_ZSET && o->encoding == OBJ_ENCODING_SKIPLIST) {        zset *zs = o->ptr;        ht = zs->dict;        count *= 2; /* We return key / value for this type. */    }    if (ht) {        void *privdata[2];        /* We set the max number of iterations to ten times the specified         * COUNT, so if the hash table is in a pathological state (very         * sparsely populated) we avoid to block too much time at the cost         * of returning no or very few elements. */        long maxiterations = count*10;        /* We pass two pointers to the callback: the list to which it will         * add new elements, and the object containing the dictionary so that         * it is possible to fetch more data in a type-dependent way. */        privdata[0] = keys;        privdata[1] = o;        do {            cursor = dictScan(ht, cursor, scanCallback, privdata);        } while (cursor &&              maxiterations-- &&              listLength(keys) < (unsigned long)count);    } else if (o->type == OBJ_SET) {        int pos = 0;        int64_t ll;        while(intsetGet(o->ptr,pos++,&ll))            listAddNodeTail(keys,createStringObjectFromLongLong(ll));        cursor = 0;    } else if (o->type == OBJ_HASH || o->type == OBJ_ZSET) {        unsigned char *p = ziplistIndex(o->ptr,0);        unsigned char *vstr;        unsigned int vlen;        long long vll;        while(p) {            ziplistGet(p,&vstr,&vlen,&vll);            listAddNodeTail(keys,                (vstr != NULL) ? createStringObject((char*)vstr,vlen) :                                 createStringObjectFromLongLong(vll));            p = ziplistNext(o->ptr,p);        }        cursor = 0;    } else {        serverPanic("Not handled encoding in SCAN.");    }    /* Step 3: Filter elements. */    node = listFirst(keys);    while (node) {        robj *kobj = listNodeValue(node);        nextnode = listNextNode(node);        int filter = 0;        /* Filter element if it does not match the pattern. */        if (!filter && use_pattern) {            if (sdsEncodedObject(kobj)) {                if (!stringmatchlen(pat, patlen, kobj->ptr, sdslen(kobj->ptr), 0))                    filter = 1;            } else {                char buf[LONG_STR_SIZE];                int len;
开发者ID:slfs007,项目名称:ZZ-Redis,代码行数:66,



注:本文中的ziplistIndex函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ zlacpy_函数代码示例
C++ ziplistGet函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。