HASH_FIND_INT(htable, &key, sPtr);
From the user guide, I see it returns whether the key exists or not. Am I right?
why to check sPtr for NULL? what does that signify?
2) In this code example,
HASH_FIND_INT(users, &user_id, s); /* id already in the hash? */
if (s==NULL) {
s = (struct my_struct *)malloc(sizeof *s);
s->id = user_id;
HASH_ADD_INT( users, id, s ); /* id: name of key field */
}
strcpy(s->name, name);
why the strcpy is called outside the if condition?
what happens if s is NOT NULL? Does that mean
if s == NULL, it means the id or the key is not in the hash already? what to do in the case?
G Hariprasad
Hi,I have few questions. Can some one please clarify?1) What does this MACRO return?HASH_FIND_INT(htable, &key, sPtr);
From the user guide, I see it returns whether the key exists or not. Am I right?
#define HASH_FIND_INT(head,findint,out) \
HASH_FIND(hh,head,findint,sizeof(int),out)
#define HASH_FIND(hh,head,keyptr,keylen,out) \
do { \
(out) = NULL; \
if (head) { \
unsigned _hf_hashv; \
HASH_VALUE(keyptr, keylen, _hf_hashv); \
HASH_FIND_BYHASHVALUE(hh, head, keyptr, keylen, _hf_hashv, out); \
} \
} while (0)
why to check sPtr for NULL? what does that signify?
2) In this code example,HASH_FIND_INT(users, &user_id, s); /* id already in the hash? */ if (s==NULL) { s = (struct my_struct *)malloc(sizeof *s); s->id = user_id; HASH_ADD_INT( users, id, s ); /* id: name of key field */ } strcpy(s->name, name);
why the strcpy is called outside the if condition? what happens if s is NOT NULL?
Does that mean
if s == NULL, it means the id or the key is not in the hash already? what to do in the case?