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
12 changed files
with
1,294 additions
and
108 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,50 @@ | ||
#include "strpool.h" | ||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
#undef uthash_nonfatal_oom | ||
#define uthash_nonfatal_oom(elt) ut_oom_recover(elt) | ||
|
||
static bool oom=false; | ||
static void ut_oom_recover(strpool *elem) | ||
{ | ||
oom=true; | ||
} | ||
|
||
bool StrPoolAddStr(strpool **pp,const char *s) | ||
{ | ||
strpool *elem; | ||
if (!(elem = (strpool*)malloc(sizeof(strpool)))) | ||
return false; | ||
if (!(elem->str = strdup(s))) | ||
{ | ||
free(elem); | ||
return false; | ||
} | ||
oom = false; | ||
HASH_ADD_KEYPTR( hh, *pp, elem->str, strlen(elem->str), elem ); | ||
if (oom) | ||
{ | ||
free(elem->str); | ||
free(elem); | ||
return false; | ||
} | ||
return true; | ||
} | ||
bool StrPoolCheckStr(strpool *p,const char *s) | ||
{ | ||
strpool *elem; | ||
HASH_FIND_STR( p, s, elem); | ||
return elem!=NULL; | ||
} | ||
|
||
void StrPoolDestroy(strpool **p) | ||
{ | ||
strpool *elem,*tmp; | ||
HASH_ITER(hh, *p, elem, tmp) { | ||
free(elem->str); | ||
HASH_DEL(*p, elem); | ||
free(elem); | ||
} | ||
*p = NULL; | ||
} |
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,18 @@ | ||
#pragma once | ||
|
||
#include <stdbool.h> | ||
#include <ctype.h> | ||
|
||
//#define HASH_BLOOM 20 | ||
#define HASH_NONFATAL_OOM 1 | ||
#define HASH_FUNCTION HASH_BER | ||
#include "uthash.h" | ||
|
||
typedef struct strpool { | ||
char *str; /* key */ | ||
UT_hash_handle hh; /* makes this structure hashable */ | ||
} strpool; | ||
|
||
void StrPoolDestroy(strpool **p); | ||
bool StrPoolAddStr(strpool **pp,const char *s); | ||
bool StrPoolCheckStr(strpool *p,const char *s); |
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
Oops, something went wrong.