本文整理汇总了C++中HASH_ADD_STR函数的典型用法代码示例。如果您正苦于以下问题:C++ HASH_ADD_STR函数的具体用法?C++ HASH_ADD_STR怎么用?C++ HASH_ADD_STR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HASH_ADD_STR函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: addToIntTable
void addToIntTable(char *sname, int *val) {
struct intVartable *s;
HASH_FIND_STR(itable, sname, s);
if(CDG_Module==1){
if (s == NULL) {
s = (struct intVartable *)malloc(sizeof(struct intVartable));
s->sname = (char *)malloc(sizeof(char) * (strlen(sname) + 1));
strcpy(s->sname, sname);
HASH_ADD_STR(itable, sname, s);
s->value = val;
}
}
else
{
if (s == NULL) {
s = (struct intVartable *)malloc(sizeof(struct intVartable));
s->sname = (char *)malloc(sizeof(char) * (strlen(sname) + 1));
strcpy(s->sname, sname);
HASH_ADD_STR(itable, sname, s);
s->value = val;
}
if(noInsertionInTables == 0)
s->value = val;
}
//printf("Added to int table: %s val: %d\n", sname,(s->value));
}
开发者ID:rajshukla,项目名称:Testgen,代码行数:35,代码来源:updateIntegerValues.c
示例2: tree_insert_model
void tree_insert_model( const char* name,
const char* prototype,
av_interface_t interface,
const char* parent_name )
{
assert(name);
if( _tree == NULL ) // i.e. nothing in the tree yet
{
// set up the root node for the sim itself
bzero(&_root,sizeof(_root));
strncpy(_root.id,"sim",strlen("sim"));
strncpy(_root.prototype, _root.id, strlen(_root.id));
_root.interface = AV_INTERFACE_SIM;
utarray_new( _root.children, &ut_str_icd ); // initialize string array
_av_node_t* rootp = &_root; // macro needs a pointer arg
HASH_ADD_STR( _tree, id, rootp );
}
assert( name && strlen(name) < NAME_LEN_MAX );
assert( parent_name == NULL || strlen(parent_name) < NAME_LEN_MAX );
// insert this new node into the tree
_av_node_t *node = malloc( sizeof(_av_node_t));
assert(node);
bzero(node,sizeof(_av_node_t));
strncpy(node->id,name,NAME_LEN_MAX);
node->interface = interface;
strncpy( node->prototype, prototype, strlen(prototype));
utarray_new( node->children, &ut_str_icd ); // initialize string array
// add the node to the tree, keyed on the name
HASH_ADD_STR( _tree, id, node );
// did something happen?
assert( _tree != NULL );
// add the child to the parent
_av_node_t *parent_node = NULL;
if( parent_name )
HASH_FIND_STR( _tree, parent_name, parent_node );
else
parent_node = &_root;
assert( parent_node );
utarray_push_back( parent_node->children, &name );
}
开发者ID:AutonomyLab,项目名称:avon,代码行数:52,代码来源:avon.c
示例3: InitStoplistConfig
void InitStoplistConfig()
{
char *stoplist_path = Config("STOPLIST");
if (stoplist_path == NULL) {
return;
}
FILE *fp = fopen(stoplist_path, "rb");
if (fp == NULL) {
fprintf(stderr, "Unable to load stoplist: %s\n", stoplist_path);
return;
}
char term[TERM_MAX_LEN+1];
for (;;) {
if (fscanf(fp, "%s\n", term) < 1) break;
strToLower(term);
Stem(term);
Stopword *newStopword;
HASH_FIND_STR(stoplist, term, newStopword);
if (newStopword == NULL) {
newStopword = malloc(sizeof(Stopword));
strcpy(newStopword->t, term);
HASH_ADD_STR(stoplist, t, newStopword);
}
}
fclose(fp);
}
开发者ID:tachappell,项目名称:topsig,代码行数:28,代码来源:topsig-stop.c
示例4: tokenset_add
int tokenset_add( struct tokenset *p, char *n )
{
struct _token *s;
HASH_FIND_STR( p->tokens, n, s );
if ( !_IS_NULL( s ) )
return s->id;
s = ( struct _token * ) malloc( sizeof ( struct _token ) );
s->text = malloc( ( 1 + strlen( n ) ) * sizeof ( char ) );
strcpy( s->text, n );
s->id = p->count;
#if 0
HASH_ADD_STR( p->tokens, text, s );
#else
HASH_ADD_KEYPTR( hh, p->tokens, s->text, strlen( s->text ), s );
#endif
p->count += 1; /* ready to map next entry */
return s->id;
}
开发者ID:crowja,项目名称:constats,代码行数:25,代码来源:tokenset.c
示例5: add_hash_entry
// internal function to insert a pair to the hash table
static void add_hash_entry(const char* function_name, funcPointerT fpt)
{
ns_t * s;
s =malloc (sizeof(ns_t));
if (!s)
{
printf("Fatal error: add_hash_entry() malloc() for s failed!\n");
assert(0);
}
#if 0
if ((s->func_name=malloc(strlen(function_name)+1)) == NULL)
{
printf("Fatal error: add_hash_entry() malloc() for s->func_name failed!\n");
assert(0);
}
else
#endif
{
strcpy(s->func_name, function_name);
s->fp = fpt;
// HASH_ADD_INT(entries, func_name,s);
HASH_ADD_STR(entries, func_name,s);
}
}
开发者ID:8l,项目名称:rose,代码行数:26,代码来源:autotuning_lib.c
示例6: fillSizes
int fillSizes(char *sizes)
/**
* Fills the hash table of chrom sizes
*
*
*
*/
{
struct lineFile *lf;
lf = lineFileOpen(sizes,TRUE);
char *line;
struct sizes_hash *s;
while(lineFileNextReal(lf,&line)){
char *split[2];
chopByWhite(line,split,2);
s = malloc(sizeof(struct sizes_hash));
strcpy(s->name, split[0]);
s->length = atoi(split[1]);
int i;
for(i=0;i<NUMSAMPLES;i++)
s->numHets[i] = 0;
HASH_ADD_STR(chrSizes,name,s);
}
return 0;
}
开发者ID:git-cambridge,项目名称:KentLib,代码行数:25,代码来源:vcfHetPerScaf.c
示例7: indexWord
/*
* indexes a word, calling other functions to check and add to hashtable
* returns 1 on success, otherwise it returns 0
*/
int indexWord( char *key, char *filename ) {
if( key == NULL || filename == NULL ) { // ya dun gooffed
return 0;
}
TokenPtr word, search;
HASH_FIND_STR(words, key, search);
// if the word exists in the hash table, check its fileNodes
if ( search ) {
// shouldn't happen in current implementation
if ( search -> fileHead == NULL ) {
addFileNode( search, filename );
} else if ( !strcmp(filename, (search->fileHead->filename)) ) { // file already exists for word
search->fileHead->tokenCount++;
} else { // file doesn't exist for word
addFileNode( search, filename );
}
} else { // word doesn't exist in the hashtable, create new word and file
if ( (word = (TokenPtr) malloc(sizeof(struct Token))) == NULL ) exit(-1);
char *newKey = (char *) malloc(sizeof(char) * strlen(key));
strcpy(newKey, key);
word -> key = newKey;
word -> fileHead = NULL;
HASH_ADD_STR( words, key, word );
addFileNode( word, filename );
}
return 1;
}
开发者ID:mc4,项目名称:Systems_Programming,代码行数:34,代码来源:indexer.c
示例8: update_timer
void update_timer( char *key, double value ) {
syslog(LOG_DEBUG, "update_timer ( %s, %f )\n", key, value);
statsd_timer_t *t;
syslog(LOG_DEBUG, "HASH_FIND_STR '%s'\n", key);
HASH_FIND_STR( timers, key, t );
syslog(LOG_DEBUG, "after HASH_FIND_STR '%s'\n", key);
if (t) {
syslog(LOG_DEBUG, "Updating old timer entry");
wait_for_timers_lock();
utarray_push_back(t->values, &value);
t->count++;
remove_timers_lock();
} else {
syslog(LOG_DEBUG, "Adding new timer entry");
t = malloc(sizeof(statsd_timer_t));
strcpy(t->key, key);
t->count = 0;
utarray_new(t->values, &timers_icd);
utarray_push_back(t->values, &value);
t->count++;
wait_for_timers_lock();
HASH_ADD_STR( timers, key, t );
remove_timers_lock();
}
}
开发者ID:ak2consulting,项目名称:statsd-c-buildpackage,代码行数:27,代码来源:statsd.c
示例9: main
int main(int argc,char *argv[])
{
name_rec *name, *names=NULL;
char linebuf[BUFLEN];
FILE *file;
file = fopen( "test11.dat", "r" );
if (file == NULL) {
perror("can't open: ");
exit(-1);
}
while (fgets(linebuf,BUFLEN,file) != NULL) {
name = (name_rec*)malloc(sizeof(name_rec));
if (name == NULL) {
exit(-1);
}
strcpy(name->boy_name, linebuf);
HASH_ADD_STR(names,boy_name,name);
}
fclose(file);
HASH_SORT(names,namecmp);
for(name=names; name!=NULL; name=(name_rec*)(name->hh.next)) {
printf("%s",name->boy_name);
}
return 0;
}
开发者ID:RamJett,项目名称:uthash,代码行数:29,代码来源:test11.c
示例10: main
int main(int argc,char *argv[]) {
name_rec *name, *names=NULL;
char linebuf[BUFLEN];
FILE *file;
int i=0,j=0;
if ( (file = fopen( "test14.dat", "r" )) == NULL ) {
perror("can't open: ");
exit(-1);
}
while (fgets(linebuf,BUFLEN,file) != NULL) {
i++;
if ( (name = (name_rec*)malloc(sizeof(name_rec))) == NULL) exit(-1);
strncpy(name->boy_name,linebuf,BUFLEN);
HASH_ADD_STR(names,boy_name,name);
}
fseek(file,0,SEEK_SET);
while (fgets(linebuf,BUFLEN,file) != NULL) {
HASH_FIND_STR(names,linebuf,name);
if (!name) printf("failed to find: %s", linebuf);
else j++;
}
fclose(file);
printf("lookup on %d of %d names succeeded\n", j, i);
return 0;
}
开发者ID:Agyar,项目名称:uthash,代码行数:29,代码来源:test14.c
示例11: main
int main(int argc, char*argv[]) {
person_t *people=NULL, *person;
const char **name;
const char * names[] = { "bob", "jack", "gary", "ty", "bo", "phil", "art",
"gil", "buck", "ted", NULL };
int id=0;
for(name=names; *name; name++) {
if ( (person = (person_t*)malloc(sizeof(person_t))) == NULL) exit(-1);
strncpy(person->first_name, *name,10);
person->id = id++;
HASH_ADD_STR(people,first_name,person);
printf("added %s (id %d)\n", person->first_name, person->id);
}
person=NULL;
person_t **p=&person;
for(name=names; *name; name++) {
HASH_FIND_STR(people,*name,*p);
if (person)
printf("found %s (id %d)\n", person->first_name, person->id);
else
printf("failed to find %s\n", *name);
}
return 0;
}
开发者ID:Agyar,项目名称:uthash,代码行数:27,代码来源:test66.c
示例12: del_vnameHash
void del_vnameHash(char* key){
vnameHash* v;
HASH_FIND_STR(vnames, key, v);
if(v != NULL){
int occ;
char find = '_';
const char *ptr = strrchr(v->vname_occ, find);
if(ptr) {
int i = strlen(v->vname_occ);
int s = ptr - v->vname_occ + 1;
char *occStr = (char*) malloc(sizeof(char)*(i-s+1));
strncpy(occStr, v->vname_occ + s, i-s);
occ = atoi(occStr);
if(occ == 0){
HASH_DEL( vnames, v);
printf("Old Hash: %s\n", v->vname_occ);
}
else{
printf("Old Hash: %s\n", v->vname_occ);
occ--;
char* newVarname_occ = (char*) malloc(sizeof(char)*(s+5));
strncpy(newVarname_occ, v->vname_occ, s);
char tmp[5];
sprintf(tmp,"%d",occ);
strcat(newVarname_occ,tmp);
HASH_DEL( vnames, v);
vnameHash* vnew = (vnameHash*)malloc(sizeof(vnameHash));
strcpy(vnew->vname_occ,newVarname_occ);
strcpy(vnew->vname,key);
printf("New Hash: %s\n", vnew->vname_occ);
HASH_ADD_STR(vnames, vname, vnew);
}
}
}
}
开发者ID:rajshukla,项目名称:Testgen,代码行数:35,代码来源:helperNew.c
示例13: MPIR_Comm_register_hint
int MPIR_Comm_register_hint(const char *hint_key, MPIR_Comm_hint_fn_t fn, void *state)
{
int mpi_errno = MPI_SUCCESS;
struct MPIR_Comm_hint_fn_elt *hint_elt = NULL;
MPID_MPI_STATE_DECL(MPID_STATE_MPIR_COMM_REGISTER_HINT);
MPID_MPI_FUNC_ENTER(MPID_STATE_MPIR_COMM_REGISTER_HINT);
if (MPID_hint_fns == NULL) {
MPIR_Add_finalize(free_hint_handles, NULL, MPIR_FINALIZE_CALLBACK_PRIO - 1);
}
hint_elt = MPIU_Malloc(sizeof(struct MPIR_Comm_hint_fn_elt));
strncpy(hint_elt->name, hint_key, MPI_MAX_INFO_KEY);
hint_elt->state = state;
hint_elt->fn = fn;
HASH_ADD_STR(MPID_hint_fns, name, hint_elt);
fn_exit:
MPID_MPI_FUNC_EXIT(MPID_STATE_MPIR_COMM_REGISTER_HINT);
return mpi_errno;
fn_fail:
goto fn_exit;
}
开发者ID:Niharikareddy,项目名称:mpich,代码行数:25,代码来源:commutil.c
示例14: main
int main(int argc,char *argv[])
{
name_rec *name, *names=NULL;
char linebuf[BUFLEN];
FILE *file;
int i=0;
if (argc != 2) {
fprintf(stderr,"usage: %s file\n", argv[0]);
exit(-1);
}
if ( (file = fopen( argv[1], "r" )) == NULL ) {
perror("can't open: ");
exit(-1);
}
while (fgets(linebuf,BUFLEN,file) != NULL) {
name = (name_rec*)malloc(sizeof(name_rec));
if (name == NULL) {
exit(-1);
}
strcpy(name->boy_name, linebuf);
HASH_ADD_STR(names,boy_name,name);
i++;
}
fprintf(stderr,"%d keys emitted.\n", i);
fclose(file);
return 0;
}
开发者ID:RamJett,项目名称:uthash,代码行数:31,代码来源:emit_keys.c
示例15: add_node
void add_node(struct Node *fileNode, void *token){
struct hash *h;
int toAdd = 0;
HASH_FIND_STR(tokenHash, token, h);
if(h == NULL){
h = (struct hash*)malloc(sizeof(struct hash));
h->token = token;
h->file = fileNode;
h->file->count = 1;
HASH_ADD_STR(tokenHash, token, h); //add this hash node to the hash table
}
else{
struct Node* ptr = h->file;
while(ptr!= NULL){ //finding the file here so we can increment its count
if(fileNode->fileName == ptr->fileName){
h->file->count++;
toAdd = 1; //this file exists in the hash and we just incremented the counter
break;
}else{
ptr = ptr->next;
}
}
if(toAdd == 0){
ptr = fileNode;
ptr->count++;
ptr->next = h->file;
h->file = ptr; //making the pointer the head of the linked list
}
}
}
开发者ID:T-G-P,项目名称:SearchMeCapn,代码行数:30,代码来源:hashadd.c
示例16: update_timer
void update_timer(char *key, double value)
{
DPRINTF("update_timer ( %s, %f )\n", key, value);
statsd_timer_t *t;
DPRINTF("HASH_FIND_STR '%s'\n", key);
HASH_FIND_STR( timers, key, t );
DPRINTF("after HASH_FIND_STR '%s'\n", key);
if (t)
{
DPRINTF("Updating old timer entry\n");
utarray_push_back(t->values, &value);
t->count++;
}
else
{
DPRINTF("Adding new timer entry\n");
t = malloc(sizeof(statsd_timer_t));
strcpy(t->key, key);
t->count = 0;
utarray_new(t->values, &timers_icd);
utarray_push_back(t->values, &value);
t->count++;
HASH_ADD_STR( timers, key, t );
}
}
开发者ID:togga,项目名称:statsd-c,代码行数:27,代码来源:counters.c
示例17: update_counter
void update_counter( char *key, double value, double sample_rate ) {
syslog(LOG_DEBUG, "update_counter ( %s, %f, %f )\n", key, value, sample_rate);
statsd_counter_t *c;
HASH_FIND_STR( counters, key, c );
if (c) {
syslog(LOG_DEBUG, "Updating old counter entry");
if (sample_rate == 0) {
wait_for_counters_lock();
c->value = c->value + value;
remove_counters_lock();
} else {
wait_for_counters_lock();
c->value = c->value + ( value * ( 1 / sample_rate ) );
remove_counters_lock();
}
} else {
syslog(LOG_DEBUG, "Adding new counter entry");
c = malloc(sizeof(statsd_counter_t));
strcpy(c->key, key);
c->value = 0;
if (sample_rate == 0) {
c->value = value;
} else {
c->value = value * ( 1 / sample_rate );
}
wait_for_counters_lock();
HASH_ADD_STR( counters, key, c );
remove_counters_lock();
}
}
开发者ID:ak2consulting,项目名称:statsd-c-buildpackage,代码行数:32,代码来源:statsd.c
示例18: add_entryToSTable
void add_entryToSTable(char *vname, char *sname, void *val, void *address, int type) {
if(getExecutionFlag() == 1) {
struct sym_table *s;
char* hash_vn = get_vnameHash(vname);
if(hash_vn != NULL) {
HASH_FIND_STR(stable, hash_vn, s);
}
else {
HASH_FIND_STR(stable, vname, s);
}
//HASH_FIND_STR(stable, vname, s);
if (s == NULL) {
s = (struct sym_table *)malloc(sizeof(struct sym_table));
s->vname = (char *)calloc((strlen(vname) + 1), sizeof(char));
strcpy(s->vname, vname);
HASH_ADD_STR(stable, vname, s);
}
s->fval = addNewFields(sname, val, address, type);
// printf("Added: %s for %s in symbol table\n", s->vname, sname);
}
}
开发者ID:rajshukla,项目名称:Testgen,代码行数:25,代码来源:symbolicExec.c
示例19: init_known_metrics
/* Initialize htable with the metrics known by the system */
int init_known_metrics()
{
/* Initialize PAPI library */
int retval;
retval = PAPI_library_init(PAPI_VER_CURRENT);
if (retval != PAPI_VER_CURRENT) {
fprintf(stderr, "Error! PAPI_library_init %d\n",retval);
PAPI_shutdown();
}
/* Initialize custom metrics storage */
HASH_CLEAR(hh, callbacks_storage);
for(int i = 0; i < available_metrics_no; ++i) {
htable *new_pair = NULL;
new_pair = malloc(sizeof(htable));
if (!new_pair) {
fprintf(stderr, "can't alloc memory for the new pair\n");
exit(-1);
}
strcpy(new_pair->key, callbacks[i].alias);
new_pair->value = callbacks[i].func;
/* insert the new pair in callbacks_storage */
HASH_ADD_STR(callbacks_storage, key, new_pair);
}
return 0;
}
开发者ID:GeorgianaElena,项目名称:Monitoring_clarisse,代码行数:34,代码来源:storage.c
示例20: hash_add_queue_kv
/*
* 函 数:hash_add_queue_kv
* 功 能:hash表中添加新的险
*/
mq_queue_t* hash_add_queue_kv(const char* qname, mq_queue_t* queue)
{
int qname_len = 0;
mq_queue_list_t* tmp_queue = NULL;
qname_len = strlen(qname);
if (qname_len < 0)
{
log_warn("Add hash fail, Invalid key");
return false;
}
tmp_queue = (mq_queue_list_t*)malloc(sizeof(mq_queue_list_t));
if (tmp_queue == NULL)
{
log_warn("Add hash fail, errno[%d], error msg[%s]", errno, strerror(errno));
return false;
}
memset(tmp_queue, '\0', sizeof(mq_queue_list_t));
/* Key setvar */
memcpy(tmp_queue->qname, qname, strlen(qname));
/* Value setvar */
memcpy(&(tmp_queue->mq_queue), queue, sizeof(mq_queue_t));
/* Qname: name of key field */
HASH_ADD_STR(g_mq_qlist, qname, tmp_queue);
return &tmp_queue->mq_queue;
}
开发者ID:bigtreetree,项目名称:ucmq,代码行数:32,代码来源:mq_queue_manage.c
注:本文中的HASH_ADD_STR函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论