forked from troydhanson/uthash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
added 10 100 | ||
id 10, tag 100 | ||
added 11 101 | ||
id 10, tag 100 | ||
id 11, tag 101 | ||
replaced 11 that had tag 101 with tag 102 | ||
id 10, tag 100 | ||
id 11, tag 102 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include "uthash.h" | ||
|
||
typedef struct hs_t { | ||
int id; | ||
int tag; | ||
UT_hash_handle hh; | ||
} hs_t; | ||
|
||
|
||
static void pr(hs_t **hdpp){ | ||
hs_t *el, *tmp, *hdp = *hdpp; | ||
HASH_ITER(hh, hdp, el, tmp){ | ||
printf("id %d, tag %d\n",el->id,el->tag); | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
|
||
hs_t *hs_head=NULL, *tmp, *replaced=NULL; | ||
|
||
tmp = (hs_t*)malloc(sizeof(hs_t)); | ||
tmp->id = 10; | ||
tmp->tag = 100; | ||
HASH_REPLACE_INT(hs_head,id,tmp,replaced); | ||
if(replaced == NULL) | ||
printf("added %d %d\n",tmp->id,tmp->tag); | ||
else | ||
printf("ERROR, ended up replacing a value, replaced: %p\n",replaced); | ||
|
||
pr(&hs_head); | ||
|
||
tmp = (hs_t*)malloc(sizeof(hs_t)); | ||
tmp->id=11; | ||
tmp->tag = 101; | ||
HASH_REPLACE_INT(hs_head,id,tmp,replaced); | ||
if(replaced == NULL) | ||
printf("added %d %d\n",tmp->id,tmp->tag); | ||
else | ||
printf("ERROR, ended up replacing a value, replaced: %p\n",replaced); | ||
|
||
pr(&hs_head); | ||
|
||
tmp = (hs_t*)malloc(sizeof(hs_t)); | ||
tmp->id=11; | ||
tmp->tag = 102; | ||
HASH_REPLACE_INT(hs_head,id,tmp,replaced); | ||
if(replaced == NULL) | ||
printf("ERROR, exected to replace a value with key: %d\n",tmp->id); | ||
else | ||
printf("replaced %d that had tag %d with tag %d\n",tmp->id,replaced->tag,tmp->tag); | ||
|
||
pr(&hs_head); | ||
|
||
return 0; | ||
} |