本文整理汇总了C++中dictAdd函数的典型用法代码示例。如果您正苦于以下问题:C++ dictAdd函数的具体用法?C++ dictAdd怎么用?C++ dictAdd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dictAdd函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
dict *d;
dictEntry *e;
d = dictCreate(&hashtype, NULL);
if (dictAdd(d, "keys", "value") == DICT_OK)
{
printf("Add value OK\n");
}
else{
printf("Add value fail\n");
return -1;
};
e = dictFind(d, "keys");
if (e)
{
printf("found: %s\n", e->v);
}
else{
printf("not found\n");
}
return 0;
}
开发者ID:fengidri,项目名称:BearCache,代码行数:25,代码来源:main.c
示例2: engine_document_found
void
engine_document_found(Engine *engine, DocBuf *buffer) {
unsigned int hash_code = buffer->hash_code;
if (!hash_code) {
hash_code = pstrhash(&buffer->doc);
}
DocRef dr = { &buffer->doc, engine->stream->written, buffer->doc.len, hash_code };
if(engine->doc_set && dictFind(engine->doc_set, &dr)){
engine->error = "duplicate document rejected";
if(engine->after_on_document) {
engine->after_on_document->handler(engine->after_on_document, engine);
}
} else {
engine->error = NULL;
dr.tmp = NULL;
engine_append_journal(engine, &buffer->doc);
ring_buffer_append_pstring(engine->stream, &buffer->doc);
ring_buffer_append(engine->docs, &dr, sizeof(dr));
long doc_id = engine_last_document_id(engine);
_engine_apply_ints(engine, buffer, doc_id);
if(engine->after_on_document) {
engine->after_on_document->handler(engine->after_on_document, engine);
}
engine_percolate(engine, buffer, doc_id);
engine_index(engine, buffer, doc_id);
if(engine->doc_set) dictAdd(engine->doc_set, &dr, NULL);
}
}
开发者ID:fizx,项目名称:sit,代码行数:28,代码来源:engine.c
示例3: setTypeAdd
/* Add the specified value into a set.
*
* If the value was already member of the set, nothing is done and 0 is
* returned, otherwise the new element is added and 1 is returned. */
int setTypeAdd(robj *subject, sds value) {
long long llval;
if (subject->encoding == OBJ_ENCODING_HT) {
dict *ht = subject->ptr;
dictEntry *de = dictAddRaw(ht,value);
if (de) {
dictSetKey(ht,de,sdsdup(value));
dictSetVal(ht,de,NULL);
return 1;
}
} else if (subject->encoding == OBJ_ENCODING_INTSET) {
if (isSdsRepresentableAsLongLong(value,&llval) == C_OK) {
uint8_t success = 0;
subject->ptr = intsetAdd(subject->ptr,llval,&success);
if (success) {
/* Convert to regular set when the intset contains
* too many entries. */
if (intsetLen(subject->ptr) > server.set_max_intset_entries)
setTypeConvert(subject,OBJ_ENCODING_HT);
return 1;
}
} else {
/* Failed to get integer from object, convert to regular set. */
setTypeConvert(subject,OBJ_ENCODING_HT);
/* The set *was* an intset and this value is not integer
* encodable, so dictAdd should always work. */
serverAssert(dictAdd(subject->ptr,sdsdup(value),NULL) == DICT_OK);
return 1;
}
} else {
serverPanic("Unknown set encoding");
}
return 0;
}
开发者ID:ericbbcc,项目名称:redis,代码行数:39,代码来源:t_set.c
示例4: lockWrite
const set *dbCreate(const sds setName)
{
set *newSet = NULL;
if (NULL == setName || 0 == strlen(setName))
{
return NULL;
}
if (NULL == (newSet = setCreate()))
return NULL;
lockWrite(sets);
if (DICT_OK != dictAdd(sets, setName, newSet))
{
unlockWrite(sets);
setDestroy(newSet);
return NULL;
}
if (0 != registerSyncObject(newSet) && 1 != syncObjectIsRegistered(newSet))
{
unlockWrite(sets);
dictDelete(sets, setName);
setDestroy(newSet);
return NULL;
}
unlockWrite(sets);
return newSet;
}
开发者ID:aquirel,项目名称:athenadb,代码行数:32,代码来源:dbengine.c
示例5: getTableId
static int getTableId(int owner, uint64_t *table_id)
{
struct dictEntry *entry = dictFind(global.tables, (void*)(intptr_t)owner);
if (entry) {
*table_id = dictGetUnsignedIntegerVal(entry);
return WHEAT_OK;
} else {
char name[256];
int l = sprintf(name, "%s_%d", hostname, owner);
name[l] = '\0';
Status s = rc_getTableId(global.client, name, table_id);
if (s != STATUS_OK) {
if (s == STATUS_TABLE_DOESNT_EXIST) {
wheatLog(WHEAT_DEBUG, "%s table %s not exists, create it, s", __func__, name);
s = rc_createTable(global.client, name, 1);
if (s != STATUS_OK) {
wheatLog(WHEAT_WARNING, "%s failed to create table %s: %s", __func__, name, statusToString(s));
return WHEAT_WRONG;
}
s = rc_getTableId(global.client, name, table_id);
}
if (s != STATUS_OK) {
wheatLog(WHEAT_WARNING, "%s failed to get table %s: %s", __func__, name, statusToString(s));
return WHEAT_WRONG;
}
}
dictAdd(global.tables, name, (void*)(intptr_t)(*table_id));
return WHEAT_OK;
}
}
开发者ID:ctbrowser,项目名称:wheatserver,代码行数:30,代码来源:app_ramcloud.c
示例6: blockForKeys
/* Set a client in blocking mode for the specified key, with the specified
* timeout */
void blockForKeys(redisClient *c, robj **keys, int numkeys, time_t timeout) {
dictEntry *de;
list *l;
int j;
c->blocking_keys = zmalloc(sizeof(robj*)*numkeys);
c->blocking_keys_num = numkeys;
c->blockingto = timeout;
for (j = 0; j < numkeys; j++) {
/* Add the key in the client structure, to map clients -> keys */
c->blocking_keys[j] = keys[j];
incrRefCount(keys[j]);
/* And in the other "side", to map keys -> clients */
de = dictFind(c->db->blocking_keys,keys[j]);
if (de == NULL) {
int retval;
/* For every key we take a list of clients blocked for it */
l = listCreate();
retval = dictAdd(c->db->blocking_keys,keys[j],l);
incrRefCount(keys[j]);
redisAssert(retval == DICT_OK);
} else {
l = dictGetEntryVal(de);
}
listAddNodeTail(l,c);
}
/* Mark the client as a blocked client */
c->flags |= REDIS_BLOCKED;
server.blpop_blocked_clients++;
}
开发者ID:aditya,项目名称:redis,代码行数:34,代码来源:t_list.c
示例7: dbAdd
/* Add the key to the DB. It's up to the caller to increment the reference
* counte of the value if needed.
*
* The program is aborted if the key already exists. */
void dbAdd(redisDb *db, robj *key, robj *val) {
sds copy = sdsdup(key->ptr);
int retval = dictAdd(db->dict, copy, val);
redisAssertWithInfo(NULL,key,retval == REDIS_OK);
if (server.cluster_enabled) SlotToKeyAdd(key);
}
开发者ID:promicr,项目名称:redis-win,代码行数:11,代码来源:db.c
示例8: luaCreateFunction
/* Define a lua function with the specified function name and body.
* The function name musts be a 2 characters long string, since all the
* functions we defined in the Lua context are in the form:
*
* f_<hex sha1 sum>
*
* On success REDIS_OK is returned, and nothing is left on the Lua stack.
* On error REDIS_ERR is returned and an appropriate error is set in the
* client context. */
int luaCreateFunction(redisClient *c, lua_State *lua, char *funcname, robj *body) {
sds funcdef = sdsempty();
funcdef = sdscat(funcdef,"function ");
funcdef = sdscatlen(funcdef,funcname,42);
funcdef = sdscatlen(funcdef,"() ",3);
funcdef = sdscatlen(funcdef,body->ptr,sdslen(body->ptr));
funcdef = sdscatlen(funcdef," end",4);
if (luaL_loadbuffer(lua,funcdef,sdslen(funcdef),"@user_script")) {
addReplyErrorFormat(c,"Error compiling script (new function): %s\n",
lua_tostring(lua,-1));
lua_pop(lua,1);
sdsfree(funcdef);
return REDIS_ERR;
}
sdsfree(funcdef);
if (lua_pcall(lua,0,0,0)) {
addReplyErrorFormat(c,"Error running script (new function): %s\n",
lua_tostring(lua,-1));
lua_pop(lua,1);
return REDIS_ERR;
}
/* We also save a SHA1 -> Original script map in a dictionary
* so that we can replicate / write in the AOF all the
* EVALSHA commands as EVAL using the original script. */
{
int retval = dictAdd(server.lua_scripts,
sdsnewlen(funcname+2,40),body);
redisAssertWithInfo(c,NULL,retval == DICT_OK);
incrRefCount(body);
}
return REDIS_OK;
}
开发者ID:343829084,项目名称:redis-storage,代码行数:44,代码来源:scripting.c
示例9: signalListAsReady
//如果有client因为等待一个key被push而被阻塞,那么将这个key放入ready_keys,key哈希表中
void signalListAsReady(redisDb *db, robj *key) {
readyList *rl;
/* No clients blocking for this key? No need to queue it. */
//如果在key不是正处于阻塞状态的键则返回
if (dictFind(db->blocking_keys,key) == NULL) return;
/* Key was already signaled? No need to queue it again. */
//key已经是ready_keys链表里的键,则返回
if (dictFind(db->ready_keys,key) != NULL) return;
/* Ok, we need to queue this key into server.ready_keys. */
//接下来需要将key添加到ready_keys中
//分配一个readyList结构的空间,该结构记录要解除client的阻塞状态的键
rl = zmalloc(sizeof(*rl));
rl->key = key; //设置要解除的键
rl->db = db; //设置所在数据库
incrRefCount(key);
//将rl添加到server.ready_keys的末尾
listAddNodeTail(server.ready_keys,rl);
/* We also add the key in the db->ready_keys dictionary in order
* to avoid adding it multiple times into a list with a simple O(1)
* check. */
//再讲key添加到ready_keys哈希表中,防止重复添加
incrRefCount(key);
serverAssert(dictAdd(db->ready_keys,key,NULL) == DICT_OK);
}
开发者ID:therenine,项目名称:redis_source_annotation,代码行数:29,代码来源:t_list.c
示例10: zmalloc
struct ProcessInfo *newProcess(pid_t pid) {
struct ProcessInfo *p = zmalloc(sizeof(struct ProcessInfo));
memset(p, 0 ,sizeof(struct ProcessInfo));
p->pid = pid;
dictAdd(server.process, &pid, p);
return p;
}
开发者ID:cinience,项目名称:saker,代码行数:7,代码来源:topbase.c
示例11: setTypeConvert
/* Convert the set to specified encoding. The resulting dict (when converting
* to a hash table) is presized to hold the number of elements in the original
* set. */
void setTypeConvert(robj *setobj, int enc) {
setTypeIterator *si;
redisAssertWithInfo(NULL,setobj,setobj->type == REDIS_SET &&
setobj->encoding == REDIS_ENCODING_INTSET);
if (enc == REDIS_ENCODING_HT) {
int64_t intele;
dict *d = dictCreate(&setDictType,NULL);
robj *element;
/* Presize the dict to avoid rehashing */
dictExpand(d,intsetLen(setobj->ptr));
/* To add the elements we extract integers and create redis objects */
si = setTypeInitIterator(setobj);
while (setTypeNext(si,&element,&intele) != -1) {
element = createStringObjectFromLongLong(intele);
redisAssertWithInfo(NULL,element,
dictAdd(d,element,NULL) == DICT_OK);
}
setTypeReleaseIterator(si);
setobj->encoding = REDIS_ENCODING_HT;
zfree(setobj->ptr);
setobj->ptr = d;
} else {
redisPanic("Unsupported set conversion");
}
}
开发者ID:wenxueliu,项目名称:draft,代码行数:32,代码来源:t_set.c
示例12: main
int main(int argc, char *argv[])
{
int ret;
dict *d = dictCreate(&testDictType, NULL);
assert(d);
Key_t *k = (Key_t*)malloc(sizeof(*k));
k->laddr = 112;
k->raddr = 112;
k->lport = 1123;
k->rport = 3306;
Val_t *v = (Val_t*)malloc(sizeof(*v));
v->v = malloc(100);
snprintf(v->v, 100, "%s", "abcdefg");
ret = dictAdd(d, k, v);
assert(ret == DICT_OK);
Val_t *v2 = dictFetchValue(d, k);
assert(0 == strcmp(v2->v, v->v));
printf("%d-%s-%s\n", ret, v->v, v2->v);
dictPrintStats(d);
dictDelete(d, k);
dictPrintStats(d);
dictRelease(d);
return 0;
}
开发者ID:AMCScarface,项目名称:misc,代码行数:34,代码来源:hash.c
示例13: conf_key_value_insert
static int
conf_key_value_insert(dict *org, sds key, conf_value *cv)
{
if(key == NULL){
log_error("ERROR: Value in conf file has no key");
return RMT_ERROR;
}
if(cv == NULL){
log_error("ERROR: Key %s in conf file has no value", key);
return RMT_ERROR;
}
if(org == NULL){
log_error("ERROR: Key %s in conf file has no organization",
key);
return RMT_ERROR;
}
if(dictAdd(org,key,cv) != DICT_OK){
log_error("ERROR: Key %s in organization of conf file is duplicate", key);
return RMT_ERROR;
}
return RMT_OK;
}
开发者ID:654894017,项目名称:redis-migrate-tool,代码行数:26,代码来源:rmt_conf.c
示例14: latencyAddSample
/* Add the specified sample to the specified time series "event".
* This function is usually called via latencyAddSampleIfNeeded(), that
* is a macro that only adds the sample if the latency is higher than
* server.latency_monitor_threshold. */
void latencyAddSample(char *event, mstime_t latency) {
struct latencyTimeSeries *ts = dictFetchValue(server.latency_events,event);
time_t now = time(NULL);
int prev;
/* Create the time series if it does not exist. */
if (ts == NULL) {
ts = zmalloc(sizeof(*ts));
ts->idx = 0;
ts->max = 0;
memset(ts->samples,0,sizeof(ts->samples));
dictAdd(server.latency_events,zstrdup(event),ts);
}
/* If the previous sample is in the same second, we update our old sample
* if this latency is > of the old one, or just return. */
prev = (ts->idx + LATENCY_TS_LEN - 1) % LATENCY_TS_LEN;
if (ts->samples[prev].time == now) {
if (latency > ts->samples[prev].latency)
ts->samples[prev].latency = latency;
return;
}
ts->samples[ts->idx].time = time(NULL);
ts->samples[ts->idx].latency = latency;
if (latency > ts->max) ts->max = latency;
ts->idx++;
if (ts->idx == LATENCY_TS_LEN) ts->idx = 0;
}
开发者ID:BruceZu,项目名称:disque,代码行数:34,代码来源:latency.c
示例15: dbAdd
/* Add the key to the DB. It's up to the caller to increment the reference
* counter of the value if needed.
*
* The program is aborted if the key already exists. */
void dbAdd(redisDb *db, robj *key, robj *val) {
sds copy = sdsdup(key->ptr);
int retval = dictAdd(db->dict, copy, val);
serverAssertWithInfo(NULL,key,retval == C_OK);
if (val->type == OBJ_LIST) signalListAsReady(db, key);
if (server.cluster_enabled) slotToKeyAdd(key);
}
开发者ID:slfs007,项目名称:ZZ-Redis,代码行数:12,代码来源:db.c
示例16: engine_search
ResultIterator *
engine_search(Engine *engine, Query *query) {
long max = engine_last_document_id(engine)+1;
ResultIterator *iter = malloc(sizeof(ResultIterator));
iter->query = query;
if(query->callback->id < 0) query->callback->id = engine->query_id++;
iter->engine = engine;
iter->doc_id = max;
iter->initialized = false;
iter->cursors = dictCreate(getTermPlistCursorDict(), 0);
iter->subs = malloc(sizeof(sub_iterator*) * query->count);
iter->count = query->count;
DEBUG("Constructing cursor");
for(int i = 0; i < query->count; i++) {
conjunction_t *cj = query->conjunctions[i];
iter->subs[i] = malloc(sizeof(sub_iterator));
iter->subs[i]->doc_id = max;
iter->subs[i]->cursors = malloc(sizeof(PlistCursor*) * cj->count);
iter->subs[i]->negateds = malloc(cj->count * sizeof(int));
iter->subs[i]->state = malloc(sizeof(long) * cj->count);
iter->subs[i]->initialized = false;
iter->subs[i]->count = cj->count;
for(int j = 0; j < cj->count; j++) {
Term *term = &cj->terms[j];
Cursor *cursor = dictFetchValue(iter->cursors, term);
if(cursor == NULL) {
switch(term->type) {
case CATCHALL:
//its an inverted null, handled later
break;
case NUMERIC:
DEBUG("Making numeric subcursor");
RingBuffer *rb = dictFetchValue(engine->ints, &term->field);
cursor = rb == NULL ? NULL : &ring_buffer_predicate_int_cursor_new(rb, sizeof(int), term->text.val[0], term->offset)->as_cursor;
break;
case TEXT:
DEBUG("Making plist subcursor for %.*s:%.*s", term->field.len, term->field.val, term->text.len, term->text.val);
Plist *pl = lrw_dict_get(engine->term_dictionary, term);
cursor = pl == NULL ? NULL : &plist_cursor_new(pl)->as_cursor;
if(!pl) {
DEBUG("term not found: using null cursor");
}
dictAdd(iter->cursors, term, cursor);
break;
default:
assert(0);
}
} else {
DEBUG("Reusing subcursor");
}
// catchall is inverted not-found
iter->subs[i]->negateds[j] = (int) ((term->type == CATCHALL) ? !term->negated : term->negated);
iter->subs[i]->cursors[j] = cursor;
iter->subs[i]->state[j] = max;
}
}
return iter;
}
开发者ID:fizx,项目名称:sit,代码行数:58,代码来源:engine.c
示例17: insertDMCFS
int insertDMCFS(columnFamilyStore *cfs)
{
if(!cfs)
return -1;
if(dictAdd(g_dataModel.cfsHashTable, cfs, NULL)
== DICT_OK)
return 0;
return -1;
}
开发者ID:yuandaxing,项目名称:c-cassandra,代码行数:9,代码来源:dataModel.c
示例18: DXDB_populateCommandTable
void DXDB_populateCommandTable(dict *server_commands) {
//printf("addDXDBfunctions: %p\n", server_commands);
int numcommands = sizeof(DXDBCommandTable)/sizeof(struct redisCommand);
for (int j = 0; j < numcommands; j++) {
struct redisCommand *c = DXDBCommandTable + j;
int retval = dictAdd(server_commands, sdsnew(c->name), c);
assert(retval == DICT_OK);
}
}
开发者ID:JakSprats,项目名称:Alchemy-Database,代码行数:9,代码来源:xdb_hooks.c
示例19: addLookupEntry
int addLookupEntry(char *key, char *value, unsigned char type)
{
lookupKey *lookKey = zmalloc(sizeof(lookupKey));
lookKey->name = strdup(key);
lookKey->type = type;
lookup_log(LOG_DEBUG, "table add %s,%d\n", key, type);
dictAdd(dt, (void *)lookKey, (void *)value);
return 0;
}
开发者ID:wudikua,项目名称:lookup,代码行数:9,代码来源:server.c
示例20: mapFDToIndex
static fdi_t mapFDToIndex(aeEventLoop *eventLoop, socket_t s)
{
fdi_t fdi = getNextFDIAvailable(eventLoop);
if (dictAdd(eventLoop->fdiMap->map, (void *)s, (void *)fdi) != DICT_OK)
{
return INVALID_FDI;
}
return fdi;
}
开发者ID:naver,项目名称:nbase-arc,代码行数:9,代码来源:ae.c
注:本文中的dictAdd函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论