本文整理汇总了C++中HASH_ADD_STR函数的典型用法代码示例。如果您正苦于以下问题:C++ HASH_ADD_STR函数的具体用法?C++ HASH_ADD_STR怎么用?C++ HASH_ADD_STR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HASH_ADD_STR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
示例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 );
}
示例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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
}
示例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;
}
示例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;
}
示例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
}
}
}