summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Roche <xroche@users.noreply.github.com>2014-06-14 10:05:44 +0000
committerXavier Roche <xroche@users.noreply.github.com>2014-06-14 10:05:44 +0000
commit7a1e4b826522ee6a12928a813b31ccb41f247d43 (patch)
tree94ff7504cebb2d33416be9eb9212b7a5175575cd
parent6c2120e0535ed51963229ca60438226fd3c3d8b9 (diff)
Renamed inthash_* API to coucal_* one.
-rw-r--r--src/coucal.c626
-rw-r--r--src/coucal.h209
-rw-r--r--src/htsback.c48
-rw-r--r--src/htscache.c16
-rw-r--r--src/htscore.c18
-rw-r--r--src/htscore.h12
-rw-r--r--src/htscoremain.c16
-rw-r--r--src/htshash.c92
-rw-r--r--src/htsindex.c10
-rw-r--r--src/htslib.c36
-rw-r--r--src/htslib.h2
-rw-r--r--src/htsopt.h6
-rw-r--r--src/htsserver.c150
-rw-r--r--src/htsserver.h6
-rw-r--r--src/htstools.c12
-rw-r--r--src/proxy/store.c92
16 files changed, 679 insertions, 672 deletions
diff --git a/src/coucal.c b/src/coucal.c
index 6b0cc36..3d1bce2 100644
--- a/src/coucal.c
+++ b/src/coucal.c
@@ -92,9 +92,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif
/** Hashtable. **/
-struct struct_inthash {
+struct struct_coucal {
/** Hashtable items. **/
- inthash_item *items;
+ coucal_item *items;
/** Log-2 of the hashtable size. **/
size_t lg_size;
@@ -105,7 +105,7 @@ struct struct_inthash {
/** Stash area for collisions. **/
struct {
/** Stash items. **/
- inthash_item items[STASH_SIZE];
+ coucal_item items[STASH_SIZE];
/** Stash size (<= STASH_SIZE). **/
size_t size;
@@ -148,52 +148,52 @@ struct struct_inthash {
/** How to handle values (might be NULL). **/
struct {
/** free() **/
- t_inthash_value_freehandler free;
+ t_coucal_value_freehandler free;
/** opaque argument **/
- inthash_opaque arg;
+ coucal_opaque arg;
} value;
/** How to handle names (might be NULL). **/
struct {
/** strdup() **/
- t_inthash_duphandler dup;
+ t_coucal_duphandler dup;
/** free() **/
- t_inthash_key_freehandler free;
+ t_coucal_key_freehandler free;
/** hash **/
- t_inthash_hasheshandler hash;
+ t_coucal_hasheshandler hash;
/** comparison **/
- t_inthash_cmphandler equals;
+ t_coucal_cmphandler equals;
/** opaque argument **/
- inthash_opaque arg;
+ coucal_opaque arg;
} key;
/** How to handle fatal assertions (might be NULL). **/
struct {
/** logging **/
- t_inthash_loghandler log;
+ t_coucal_loghandler log;
/** abort() **/
- t_inthash_asserthandler fatal;
+ t_coucal_asserthandler fatal;
/** opaque argument **/
- inthash_opaque arg;
+ coucal_opaque arg;
/** hashtable name for logging **/
- inthash_key_const name;
+ coucal_key_const name;
} error;
/** How to handle pretty-print (debug) (might be NULL). **/
struct {
/** key print() **/
- t_inthash_printkeyhandler key;
+ t_coucal_printkeyhandler key;
/** value print() **/
- t_inthash_printvaluehandler value;
+ t_coucal_printvaluehandler value;
/** opaque argument **/
- inthash_opaque arg;
+ coucal_opaque arg;
} print;
} custom;
};
/* Assertion check. */
-#define inthash_assert(HASHTABLE, EXP) \
- (void)( (EXP) || (inthash_assert_failed(HASHTABLE, #EXP, __FILE__, __LINE__), 0) )
+#define coucal_assert(HASHTABLE, EXP) \
+ (void)( (EXP) || (coucal_assert_failed(HASHTABLE, #EXP, __FILE__, __LINE__), 0) )
/* Compiler-specific. */
#ifdef __GNUC__
@@ -208,38 +208,38 @@ struct struct_inthash {
#endif
/* Logging level. */
-static void inthash_log(const inthash hashtable, inthash_loglevel level,
+static void coucal_log(const coucal hashtable, coucal_loglevel level,
const char *format, va_list args);
#define DECLARE_LOG_FUNCTION(NAME, LEVEL) \
-static void NAME(const inthash hashtable, const char *format, ...) \
+static void NAME(const coucal hashtable, const char *format, ...) \
INTHASH_PRINTF_FUN(2, 3); \
-static void NAME(const inthash hashtable, const char *format, ...) { \
+static void NAME(const coucal hashtable, const char *format, ...) { \
va_list args; \
va_start(args, format); \
- inthash_log(hashtable, LEVEL, format, args); \
+ coucal_log(hashtable, LEVEL, format, args); \
va_end(args); \
}
#if 0
/* Verbose. */
-DECLARE_LOG_FUNCTION(inthash_crit, inthash_log_critical)
-DECLARE_LOG_FUNCTION(inthash_warning, inthash_log_warning)
-DECLARE_LOG_FUNCTION(inthash_info, inthash_log_info)
-DECLARE_LOG_FUNCTION(inthash_debug, inthash_log_debug)
-DECLARE_LOG_FUNCTION(inthash_trace, inthash_log_trace)
+DECLARE_LOG_FUNCTION(coucal_crit, coucal_log_critical)
+DECLARE_LOG_FUNCTION(coucal_warning, coucal_log_warning)
+DECLARE_LOG_FUNCTION(coucal_info, coucal_log_info)
+DECLARE_LOG_FUNCTION(coucal_debug, coucal_log_debug)
+DECLARE_LOG_FUNCTION(coucal_trace, coucal_log_trace)
#elif 0
/* Info. */
-DECLARE_LOG_FUNCTION(inthash_crit, inthash_log_critical)
-DECLARE_LOG_FUNCTION(inthash_warning, inthash_log_warning)
-DECLARE_LOG_FUNCTION(inthash_info, inthash_log_info)
-#define inthash_debug inthash_log
-#define inthash_trace inthash_nolog
+DECLARE_LOG_FUNCTION(coucal_crit, coucal_log_critical)
+DECLARE_LOG_FUNCTION(coucal_warning, coucal_log_warning)
+DECLARE_LOG_FUNCTION(coucal_info, coucal_log_info)
+#define coucal_debug coucal_log
+#define coucal_trace coucal_nolog
#else
/* No logging except stats and critical. */
-DECLARE_LOG_FUNCTION(inthash_crit, inthash_log_critical)
-DECLARE_LOG_FUNCTION(inthash_warning, inthash_log_warning)
-DECLARE_LOG_FUNCTION(inthash_info, inthash_log_info)
-#define inthash_debug inthash_nolog
-#define inthash_trace inthash_nolog
+DECLARE_LOG_FUNCTION(coucal_crit, coucal_log_critical)
+DECLARE_LOG_FUNCTION(coucal_warning, coucal_log_warning)
+DECLARE_LOG_FUNCTION(coucal_info, coucal_log_info)
+#define coucal_debug coucal_nolog
+#define coucal_trace coucal_nolog
#endif
/* 2**X */
@@ -249,37 +249,37 @@ DECLARE_LOG_FUNCTION(inthash_info, inthash_log_info)
static char the_empty_string[1] = { 0 };
/* global assertion handler */
-static t_inthash_asserthandler global_assert_handler = NULL;
+static t_coucal_asserthandler global_assert_handler = NULL;
/* global assertion handler */
-static t_inthash_loghandler global_log_handler = NULL;
+static t_coucal_loghandler global_log_handler = NULL;
/* default assertion handler, if neither hashtable one nor global one
were defined */
-static void inthash_fail(const char* exp, const char* file, int line) {
+static void coucal_fail(const char* exp, const char* file, int line) {
fprintf(stderr, "assertion '%s' failed at %s:%d\n", exp, file, line);
abort();
}
/* assert failed handler. */
-static void inthash_assert_failed(const inthash hashtable, const char* exp, const char* file, int line) {
- const char *const name = inthash_get_name(hashtable);
- inthash_crit(hashtable, "hashtable %s: %s failed at %s:%d",
+static void coucal_assert_failed(const coucal hashtable, const char* exp, const char* file, int line) {
+ const char *const name = coucal_get_name(hashtable);
+ coucal_crit(hashtable, "hashtable %s: %s failed at %s:%d",
name != NULL ? name : "<unknown>", exp, file, line);
if (hashtable != NULL && hashtable->custom.error.fatal != NULL) {
hashtable->custom.error.fatal(hashtable->custom.error.arg, exp, file, line);
} else if (global_assert_handler != NULL) {
global_assert_handler(hashtable, exp, file, line);
} else {
- inthash_fail(exp, file, line);
+ coucal_fail(exp, file, line);
}
abort();
}
/* Logging */
-static void inthash_log(const inthash hashtable, inthash_loglevel level,
- const char *format, va_list args) {
- inthash_assert(hashtable, format != NULL);
+static void coucal_log(const coucal hashtable, coucal_loglevel level,
+ const char *format, va_list args) {
+ coucal_assert(hashtable, format != NULL);
if (hashtable != NULL && hashtable->custom.error.log != NULL) {
hashtable->custom.error.log(hashtable->custom.error.arg, level, format, args);
} else if (global_log_handler != NULL) {
@@ -292,20 +292,20 @@ static void inthash_log(const inthash hashtable, inthash_loglevel level,
}
/* No logging (should be dropped by the compiler) */
-static void inthash_nolog(const inthash hashtable, const char *format, ...)
- INTHASH_PRINTF_FUN(2, 3);
-static void inthash_nolog(const inthash hashtable, const char *format, ...) {
+static void coucal_nolog(const coucal hashtable, const char *format, ...)
+ INTHASH_PRINTF_FUN(2, 3);
+static void coucal_nolog(const coucal hashtable, const char *format, ...) {
(void) hashtable;
(void) format;
}
-const char* inthash_get_name(inthash hashtable) {
+const char* coucal_get_name(coucal hashtable) {
return hashtable->custom.error.name;
}
-static void inthash_log_stats(inthash hashtable) {
- const char *const name = inthash_get_name(hashtable);
- inthash_info(hashtable, "hashtable %s%s%ssummary: "
+static void coucal_log_stats(coucal hashtable) {
+ const char *const name = coucal_get_name(hashtable);
+ coucal_info(hashtable, "hashtable %s%s%ssummary: "
"size=%"UINT_64_FORMAT" (lg2=%"UINT_64_FORMAT") "
"used=%"UINT_64_FORMAT" "
"stash-size=%"UINT_64_FORMAT" "
@@ -341,19 +341,19 @@ static void inthash_log_stats(inthash hashtable) {
(uint64_t) hashtable->stats.rehash_count,
(uint64_t) hashtable->stats.pool_compact_count,
(uint64_t) hashtable->stats.pool_realloc_count,
- (uint64_t) inthash_memory_size(hashtable)
+ (uint64_t) coucal_memory_size(hashtable)
);
}
/* default hash function when key is a regular C-string */
-inthash_hashkeys inthash_hash_string(const char *name) {
+coucal_hashkeys coucal_hash_string(const char *name) {
#if HTS_INTHASH_USES_MD5 == 1
/* compute a regular MD5 and extract two 32-bit integers */
MD5_CTX ctx;
union {
unsigned char md5digest[16];
- inthash_hashkeys mhashes[2];
- inthash_hashkeys hashes;
+ coucal_hashkeys mhashes[2];
+ coucal_hashkeys hashes;
} u;
/* compute MD5 */
@@ -375,7 +375,7 @@ inthash_hashkeys inthash_hash_string(const char *name) {
#elif (defined(HTS_INTHASH_USES_MURMUR))
union {
uint32_t result[4];
- inthash_hashkeys hashes;
+ coucal_hashkeys hashes;
} u;
MurmurHash3_x86_128(name, (const int) strlen(name),
42, &u.result) ;
@@ -394,7 +394,7 @@ inthash_hashkeys inthash_hash_string(const char *name) {
/* compute two Fowler-Noll-Vo hashes (64-bit FNV-1 variant) ;
each 64-bit hash being XOR-folded into a single 32-bit hash. */
size_t i;
- inthash_hashkeys hashes;
+ coucal_hashkeys hashes;
uint64_t h1, h2;
/* FNV-1, 64-bit. */
@@ -427,46 +427,46 @@ inthash_hashkeys inthash_hash_string(const char *name) {
#endif
}
-static INTHASH_INLINE inthash_hashkeys inthash_calc_hashes(inthash hashtable,
- inthash_key_const value) {
+static INTHASH_INLINE coucal_hashkeys coucal_calc_hashes(coucal hashtable,
+ coucal_key_const value) {
return hashtable->custom.key.hash == NULL
- ? inthash_hash_string(value)
+ ? coucal_hash_string(value)
: hashtable->custom.key.hash(hashtable->custom.key.arg, value);
}
/* position 'pos' is free ? */
-static INTHASH_INLINE int inthash_is_free(const inthash hashtable, size_t pos) {
+static INTHASH_INLINE int coucal_is_free(const coucal hashtable, size_t pos) {
return hashtable->items[pos].name == NULL;
}
/* compare two keys ; by default using strcmp() */
-static INTHASH_INLINE int inthash_equals(inthash hashtable,
- inthash_key_const a,
- inthash_key_const b) {
+static INTHASH_INLINE int coucal_equals(coucal hashtable,
+ coucal_key_const a,
+ coucal_key_const b) {
return hashtable->custom.key.equals == NULL
? strcmp((const char*) a, (const char*) b) == 0
: hashtable->custom.key.equals(hashtable->custom.key.arg, a, b);
}
-static INTHASH_INLINE int inthash_matches_(inthash hashtable,
- const inthash_item *const item,
- inthash_key_const name,
- const inthash_hashkeys *hashes) {
+static INTHASH_INLINE int coucal_matches_(coucal hashtable,
+ const coucal_item *const item,
+ coucal_key_const name,
+ const coucal_hashkeys *hashes) {
return item->name != NULL
&& item->hashes.hash1 == hashes->hash1
&& item->hashes.hash2 == hashes->hash2
- && inthash_equals(hashtable, item->name, name);
+ && coucal_equals(hashtable, item->name, name);
}
-static INTHASH_INLINE int inthash_matches(inthash hashtable, size_t pos,
- inthash_key_const name,
- const inthash_hashkeys *hashes) {
- const inthash_item *const item = &hashtable->items[pos];
- return inthash_matches_(hashtable, item, name, hashes);
+static INTHASH_INLINE int coucal_matches(coucal hashtable, size_t pos,
+ coucal_key_const name,
+ const coucal_hashkeys *hashes) {
+ const coucal_item *const item = &hashtable->items[pos];
+ return coucal_matches_(hashtable, item, name, hashes);
}
/* compact string pool ; does not change the capacity */
-static void inthash_compact_pool(inthash hashtable, size_t capacity) {
+static void coucal_compact_pool(coucal hashtable, size_t capacity) {
const size_t hash_size = POW2(hashtable->lg_size);
size_t i;
char*const old_pool = hashtable->pool.buffer;
@@ -474,7 +474,7 @@ static void inthash_compact_pool(inthash hashtable, size_t capacity) {
size_t count = 0;
/* we manage the string pool */
- inthash_assert(hashtable, hashtable->custom.key.dup == NULL);
+ coucal_assert(hashtable, hashtable->custom.key.dup == NULL);
/* statistics */
hashtable->stats.pool_compact_count++;
@@ -489,11 +489,11 @@ static void inthash_compact_pool(inthash hashtable, size_t capacity) {
hashtable->pool.size = 0;
hashtable->pool.used = 0;
if (hashtable->pool.buffer == NULL) {
- inthash_debug(hashtable,
+ coucal_debug(hashtable,
"** hashtable string pool compaction error: could not allocate "
"%"UINT_64_FORMAT" bytes",
(uint64_t) hashtable->pool.capacity);
- inthash_assert(hashtable, ! "hashtable string pool compaction error");
+ coucal_assert(hashtable, ! "hashtable string pool compaction error");
}
/* relocate a string on a different pool */
@@ -506,17 +506,17 @@ static void inthash_compact_pool(inthash hashtable, size_t capacity) {
char *const max_dest = \
&hashtable->pool.buffer[capacity]; \
/* copy string */ \
- inthash_assert(hashtable, dest < max_dest); \
+ coucal_assert(hashtable, dest < max_dest); \
dest[0] = src[0]; \
{ \
size_t i; \
for(i = 1 ; src[i - 1] != '\0' ; i++) { \
- inthash_assert(hashtable, &dest[i] < max_dest); \
+ coucal_assert(hashtable, &dest[i] < max_dest); \
dest[i] = src[i]; \
} \
/* update pool size */ \
hashtable->pool.size += i; \
- inthash_assert(hashtable, \
+ coucal_assert(hashtable, \
hashtable->pool.size <= capacity); \
} \
/* update source */ \
@@ -541,7 +541,7 @@ static void inthash_compact_pool(inthash hashtable, size_t capacity) {
/* wipe previous pool */
free(old_pool);
- inthash_debug(hashtable,
+ coucal_debug(hashtable,
"compacted string pool for %"UINT_64_FORMAT" strings: "
"%"UINT_64_FORMAT" bytes => %"UINT_64_FORMAT" bytes",
(uint64_t) count, (uint64_t) old_size,
@@ -549,18 +549,18 @@ static void inthash_compact_pool(inthash hashtable, size_t capacity) {
}
/* realloc (expand) string pool ; does not change the compacity */
-static void inthash_realloc_pool(inthash hashtable, size_t capacity) {
+static void coucal_realloc_pool(coucal hashtable, size_t capacity) {
const size_t hash_size = POW2(hashtable->lg_size);
char *const oldbase = hashtable->pool.buffer;
size_t i;
size_t count = 0;
/* we manage the string pool */
- inthash_assert(hashtable, hashtable->custom.key.dup == NULL);
+ coucal_assert(hashtable, hashtable->custom.key.dup == NULL);
/* compact instead ? */
if (hashtable->pool.used < ( hashtable->pool.size*3 ) / 4) {
- inthash_compact_pool(hashtable, capacity);
+ coucal_compact_pool(hashtable, capacity);
return ;
}
@@ -574,18 +574,18 @@ static void inthash_realloc_pool(inthash hashtable, size_t capacity) {
hashtable->pool.buffer = realloc(hashtable->pool.buffer,
hashtable->pool.capacity);
if (hashtable->pool.buffer == NULL) {
- inthash_crit(hashtable,
+ coucal_crit(hashtable,
"** hashtable string pool allocation error: could not allocate "
"%"UINT_64_FORMAT" bytes",
(uint64_t) hashtable->pool.capacity);
- inthash_assert(hashtable, ! "hashtable string pool allocation error");
+ coucal_assert(hashtable, ! "hashtable string pool allocation error");
}
/* recompute string address */
#define RECOMPUTE_STRING(S) do { \
if (S != NULL && S != the_empty_string) { \
const size_t offset = (const char*) (S) - oldbase; \
- inthash_assert(hashtable, offset < hashtable->pool.capacity); \
+ coucal_assert(hashtable, offset < hashtable->pool.capacity); \
S = &hashtable->pool.buffer[offset]; \
count++; \
} \
@@ -601,13 +601,13 @@ static void inthash_realloc_pool(inthash hashtable, size_t capacity) {
#undef RECOMPUTE_STRING
- inthash_debug(hashtable, "reallocated string pool for "
+ coucal_debug(hashtable, "reallocated string pool for "
"%"UINT_64_FORMAT" strings: %"UINT_64_FORMAT" bytes",
(uint64_t) count, (uint64_t) hashtable->pool.capacity);
}
-static inthash_key inthash_dup_name_internal(inthash hashtable,
- inthash_key_const name_) {
+static coucal_key coucal_dup_name_internal(coucal hashtable,
+ coucal_key_const name_) {
const char *const name = (const char*) name_;
const size_t len = strlen(name) + 1;
char *s;
@@ -615,22 +615,22 @@ static inthash_key inthash_dup_name_internal(inthash hashtable,
/* the pool does not allow empty strings for safety purpose ; handhe that
(keys are being emptied when free'd to detect duplicate free) */
if (len == 1) {
- inthash_assert(hashtable, the_empty_string[0] == '\0');
+ coucal_assert(hashtable, the_empty_string[0] == '\0');
return the_empty_string;
}
/* expand pool capacity */
- inthash_assert(hashtable, hashtable->pool.size <= hashtable->pool.capacity);
+ coucal_assert(hashtable, hashtable->pool.size <= hashtable->pool.capacity);
if (hashtable->pool.capacity - hashtable->pool.size < len) {
size_t capacity;
for(capacity = MIN_POOL_CAPACITY ; capacity < hashtable->pool.size + len
; capacity <<= 1) ;
- inthash_assert(hashtable, hashtable->pool.size < capacity);
- inthash_realloc_pool(hashtable, capacity);
+ coucal_assert(hashtable, hashtable->pool.size < capacity);
+ coucal_realloc_pool(hashtable, capacity);
}
/* copy */
- inthash_assert(hashtable, len + hashtable->pool.size <= hashtable->pool.capacity);
+ coucal_assert(hashtable, len + hashtable->pool.size <= hashtable->pool.capacity);
s = &hashtable->pool.buffer[hashtable->pool.size];
memcpy(s, name, len);
hashtable->pool.size += len;
@@ -640,26 +640,26 @@ static inthash_key inthash_dup_name_internal(inthash hashtable,
}
/* duplicate a key. default is to use the internal pool. */
-static INTHASH_INLINE inthash_key inthash_dup_name(inthash hashtable,
- inthash_key_const name) {
+static INTHASH_INLINE coucal_key coucal_dup_name(coucal hashtable,
+ coucal_key_const name) {
return hashtable->custom.key.dup == NULL
- ? inthash_dup_name_internal(hashtable, name)
+ ? coucal_dup_name_internal(hashtable, name)
: hashtable->custom.key.dup(hashtable->custom.key.arg, name);
}
/* internal pool free handler.
note: pointer must have been kicked from the pool first */
-static void inthash_free_key_internal(inthash hashtable, inthash_key name_) {
+static void coucal_free_key_internal(coucal hashtable, coucal_key name_) {
char *const name = (char*) name_;
const size_t len = strlen(name) + 1;
- /* see inthash_dup_name_internal() handling */
+ /* see coucal_dup_name_internal() handling */
if (len == 1 && name == the_empty_string) {
- inthash_assert(hashtable, the_empty_string[0] == '\0');
+ coucal_assert(hashtable, the_empty_string[0] == '\0');
return ;
}
- inthash_assert(hashtable, *name != '\0' || !"duplicate or bad string pool release");
+ coucal_assert(hashtable, *name != '\0' || !"duplicate or bad string pool release");
hashtable->pool.used -= len;
*name = '\0'; /* the string is now invalidated */
@@ -670,117 +670,117 @@ static void inthash_free_key_internal(inthash hashtable, inthash_key name_) {
if (hashtable->pool.used < capacity / 4) {
capacity /= 2;
}
- inthash_assert(hashtable, hashtable->pool.used < capacity);
- inthash_compact_pool(hashtable, capacity);
+ coucal_assert(hashtable, hashtable->pool.used < capacity);
+ coucal_compact_pool(hashtable, capacity);
}
}
/* free a key. default is to use the internal pool.
note: pointer must have been kicked from the pool first */
-static void inthash_free_key(inthash hashtable, inthash_key name) {
+static void coucal_free_key(coucal hashtable, coucal_key name) {
if (hashtable->custom.key.free == NULL) {
- inthash_free_key_internal(hashtable, name);
+ coucal_free_key_internal(hashtable, name);
} else {
hashtable->custom.key.free(hashtable->custom.key.arg, name);
}
}
-static INTHASH_INLINE size_t inthash_hash_to_pos_(size_t lg_size,
- inthash_hashkey hash) {
- const inthash_hashkey mask = POW2(lg_size) - 1;
+static INTHASH_INLINE size_t coucal_hash_to_pos_(size_t lg_size,
+ coucal_hashkey hash) {
+ const coucal_hashkey mask = POW2(lg_size) - 1;
return hash & mask;
}
-static INTHASH_INLINE size_t inthash_hash_to_pos(const inthash hashtable,
- inthash_hashkey hash) {
- return inthash_hash_to_pos_(hashtable->lg_size, hash);
+static INTHASH_INLINE size_t coucal_hash_to_pos(const coucal hashtable,
+ coucal_hashkey hash) {
+ return coucal_hash_to_pos_(hashtable->lg_size, hash);
}
-int inthash_read_pvoid(inthash hashtable, inthash_key_const name, void **pvalue) {
- inthash_value value = INTHASH_VALUE_NULL;
+int coucal_read_pvoid(coucal hashtable, coucal_key_const name, void **pvalue) {
+ coucal_value value = INTHASH_VALUE_NULL;
const int ret =
- inthash_read_value(hashtable, name, (pvalue != NULL) ? &value : NULL);
+ coucal_read_value(hashtable, name, (pvalue != NULL) ? &value : NULL);
if (pvalue != NULL)
*pvalue = value.ptr;
return ret;
}
-int inthash_write_pvoid(inthash hashtable, inthash_key_const name, void *pvalue) {
- inthash_value value = INTHASH_VALUE_NULL;
+int coucal_write_pvoid(coucal hashtable, coucal_key_const name, void *pvalue) {
+ coucal_value value = INTHASH_VALUE_NULL;
value.ptr = pvalue;
- return inthash_write_value(hashtable, name, value);
+ return coucal_write_value(hashtable, name, value);
}
-void inthash_add_pvoid(inthash hashtable, inthash_key_const name, void *pvalue) {
- inthash_value value = INTHASH_VALUE_NULL;
+void coucal_add_pvoid(coucal hashtable, coucal_key_const name, void *pvalue) {
+ coucal_value value = INTHASH_VALUE_NULL;
value.ptr = pvalue;
- inthash_write_value(hashtable, name, value);
+ coucal_write_value(hashtable, name, value);
}
-int inthash_write(inthash hashtable, inthash_key_const name, intptr_t intvalue) {
- inthash_value value = INTHASH_VALUE_NULL;
+int coucal_write(coucal hashtable, coucal_key_const name, intptr_t intvalue) {
+ coucal_value value = INTHASH_VALUE_NULL;
value.intg = intvalue;
- return inthash_write_value(hashtable, name, value);
+ return coucal_write_value(hashtable, name, value);
}
-static void inthash_default_free_handler(inthash_opaque arg,
- inthash_value value) {
+static void coucal_default_free_handler(coucal_opaque arg,
+ coucal_value value) {
(void) arg;
if (value.ptr != NULL)
free(value.ptr);
}
-static void inthash_del_value_(inthash hashtable, inthash_value *pvalue) {
+static void coucal_del_value_(coucal hashtable, coucal_value *pvalue) {
if (hashtable->custom.value.free != NULL)
hashtable->custom.value.free(hashtable->custom.value.arg, *pvalue);
pvalue->ptr = NULL;
}
-static void inthash_del_value(inthash hashtable, size_t pos) {
- inthash_del_value_(hashtable, &hashtable->items[pos].value);
+static void coucal_del_value(coucal hashtable, size_t pos) {
+ coucal_del_value_(hashtable, &hashtable->items[pos].value);
}
-static void inthash_del_name(inthash hashtable, inthash_item *item) {
- const inthash_hashkeys nullHash = INTHASH_KEYS_NULL;
+static void coucal_del_name(coucal hashtable, coucal_item *item) {
+ const coucal_hashkeys nullHash = INTHASH_KEYS_NULL;
char *const name = (char*) item->name;
item->name = NULL; /* there must be no reference remaining */
item->hashes = nullHash;
/* free after detach (we may compact the pool) */
- inthash_free_key(hashtable, name);
+ coucal_free_key(hashtable, name);
}
-static void inthash_del_item(inthash hashtable, inthash_item *pitem) {
- inthash_del_value_(hashtable, &pitem->value);
- inthash_del_name(hashtable, pitem);
+static void coucal_del_item(coucal hashtable, coucal_item *pitem) {
+ coucal_del_value_(hashtable, &pitem->value);
+ coucal_del_name(hashtable, pitem);
}
-static int inthash_add_item_(inthash hashtable, inthash_item item);
+static int coucal_add_item_(coucal hashtable, coucal_item item);
/* Write (add or replace) a value in the hashtable. */
-static int inthash_write_value_(inthash hashtable, inthash_key_const name,
- inthash_value value) {
- inthash_item item;
+static int coucal_write_value_(coucal hashtable, coucal_key_const name,
+ coucal_value value) {
+ coucal_item item;
size_t pos;
- const inthash_hashkeys hashes = inthash_calc_hashes(hashtable, name);
+ const coucal_hashkeys hashes = coucal_calc_hashes(hashtable, name);
/* Statistics */
hashtable->stats.write_count++;
/* replace at position 1 ? */
- pos = inthash_hash_to_pos(hashtable, hashes.hash1);
- if (inthash_matches(hashtable, pos, name, &hashes)) {
- inthash_del_value(hashtable, pos);
+ pos = coucal_hash_to_pos(hashtable, hashes.hash1);
+ if (coucal_matches(hashtable, pos, name, &hashes)) {
+ coucal_del_value(hashtable, pos);
hashtable->items[pos].value = value;
return 0; /* replaced */
}
/* replace at position 2 ? */
- pos = inthash_hash_to_pos(hashtable, hashes.hash2);
- if (inthash_matches(hashtable, pos, name, &hashes)) {
- inthash_del_value(hashtable, pos);
+ pos = coucal_hash_to_pos(hashtable, hashes.hash2);
+ if (coucal_matches(hashtable, pos, name, &hashes)) {
+ coucal_del_value(hashtable, pos);
hashtable->items[pos].value = value;
return 0; /* replaced */
}
@@ -789,9 +789,9 @@ static int inthash_write_value_(inthash hashtable, inthash_key_const name,
if (hashtable->stash.size != 0) {
size_t i;
for(i = 0 ; i < hashtable->stash.size ; i++) {
- if (inthash_matches_(hashtable, &hashtable->stash.items[i], name,
+ if (coucal_matches_(hashtable, &hashtable->stash.items[i], name,
&hashes)) {
- inthash_del_value_(hashtable, &hashtable->stash.items[i].value);
+ coucal_del_value_(hashtable, &hashtable->stash.items[i].value);
hashtable->stash.items[i].value = value;
return 0; /* replaced */
}
@@ -802,68 +802,68 @@ static int inthash_write_value_(inthash hashtable, inthash_key_const name,
hashtable->stats.add_count++;
/* otherwise we need to create a new item */
- item.name = inthash_dup_name(hashtable, name);
+ item.name = coucal_dup_name(hashtable, name);
item.value = value;
item.hashes = hashes;
- return inthash_add_item_(hashtable, item);
+ return coucal_add_item_(hashtable, item);
}
/* Return the string representation of a key */
-static const char* inthash_print_key(inthash hashtable,
- inthash_key_const name) {
+static const char* coucal_print_key(coucal hashtable,
+ coucal_key_const name) {
return hashtable->custom.print.key != NULL
? hashtable->custom.print.key(hashtable->custom.print.arg, name)
: (const char*) name;
}
/* Add a new item in the hashtable. The item SHALL NOT be alreasy present. */
-static int inthash_add_item_(inthash hashtable, inthash_item item) {
- inthash_hashkey cuckoo_hash, initial_cuckoo_hash;
+static int coucal_add_item_(coucal hashtable, coucal_item item) {
+ coucal_hashkey cuckoo_hash, initial_cuckoo_hash;
size_t loops;
size_t pos;
/* place at free position 1 ? */
- pos = inthash_hash_to_pos(hashtable, item.hashes.hash1);
- if (inthash_is_free(hashtable, pos)) {
+ pos = coucal_hash_to_pos(hashtable, item.hashes.hash1);
+ if (coucal_is_free(hashtable, pos)) {
hashtable->items[pos] = item;
return 1; /* added */
} else {
/* place at free position 2 ? */
- pos = inthash_hash_to_pos(hashtable, item.hashes.hash2);
- if (inthash_is_free(hashtable, pos)) {
+ pos = coucal_hash_to_pos(hashtable, item.hashes.hash2);
+ if (coucal_is_free(hashtable, pos)) {
hashtable->items[pos] = item;
return 1; /* added */
}
/* prepare cuckoo ; let's take position 1 */
else {
cuckoo_hash = initial_cuckoo_hash = item.hashes.hash1;
- inthash_trace(hashtable,
+ coucal_trace(hashtable,
"debug:collision with '%s' at %"UINT_64_FORMAT" (%x)",
- inthash_print_key(hashtable, item.name),
+ coucal_print_key(hashtable, item.name),
(uint64_t) pos, cuckoo_hash);
}
}
/* put 'item' in place with hash 'cuckoo_hash' */
for(loops = POW2(hashtable->lg_size) ; loops != 0 ; --loops) {
- const size_t pos = inthash_hash_to_pos(hashtable, cuckoo_hash);
+ const size_t pos = coucal_hash_to_pos(hashtable, cuckoo_hash);
- inthash_trace(hashtable,
+ coucal_trace(hashtable,
"\tdebug:placing cuckoo '%s' at %"UINT_64_FORMAT" (%x)",
- inthash_print_key(hashtable, item.name),
+ coucal_print_key(hashtable, item.name),
(uint64_t) pos, cuckoo_hash);
/* place at alternate free position ? */
- if (inthash_is_free(hashtable, pos)) {
- inthash_trace(hashtable, "debug:free position");
+ if (coucal_is_free(hashtable, pos)) {
+ coucal_trace(hashtable, "debug:free position");
hashtable->items[pos] = item;
return 1; /* added */
}
/* then cuckoo's place it is */
else {
/* replace */
- const inthash_item backup_item = hashtable->items[pos];
+ const coucal_item backup_item = hashtable->items[pos];
hashtable->items[pos] = item;
/* statistics */
@@ -873,19 +873,19 @@ static int inthash_add_item_(inthash hashtable, inthash_item item) {
item = backup_item;
/* we just kicked this item from its position 1 */
- if (pos == inthash_hash_to_pos(hashtable, item.hashes.hash1)) {
+ if (pos == coucal_hash_to_pos(hashtable, item.hashes.hash1)) {
/* then place it on position 2 on next run */
- inthash_trace(hashtable, "\tdebug:position 1");
+ coucal_trace(hashtable, "\tdebug:position 1");
cuckoo_hash = item.hashes.hash2;
}
/* we just kicked this item from its position 2 */
- else if (pos == inthash_hash_to_pos(hashtable, item.hashes.hash2)) {
+ else if (pos == coucal_hash_to_pos(hashtable, item.hashes.hash2)) {
/* then place it on position 1 on next run */
- inthash_trace(hashtable, "\tdebug:position 2");
+ coucal_trace(hashtable, "\tdebug:position 2");
cuckoo_hash = item.hashes.hash1;
}
else {
- inthash_assert(hashtable, ! "hashtable internal error: unexpected position");
+ coucal_assert(hashtable, ! "hashtable internal error: unexpected position");
}
/* we are looping (back to same hash) */
@@ -906,7 +906,7 @@ static int inthash_add_item_(inthash hashtable, inthash_item item) {
if (hashtable->stash.size > hashtable->stats.max_stash_size) {
hashtable->stats.max_stash_size = hashtable->stash.size;
}
- inthash_debug(hashtable, "used stash because of collision (%d entries)",
+ coucal_debug(hashtable, "used stash because of collision (%d entries)",
(int) hashtable->stash.size);
return 1; /* added */
} else {
@@ -915,46 +915,46 @@ static int inthash_add_item_(inthash hashtable, inthash_item item) {
&& hashtable->custom.print.value != NULL) {
size_t i;
for(i = 0 ; i < hashtable->stash.size ; i++) {
- inthash_item *const item = &hashtable->stash.items[i];
- const size_t pos1 = inthash_hash_to_pos(hashtable, item->hashes.hash1);
- const size_t pos2 = inthash_hash_to_pos(hashtable, item->hashes.hash2);
- inthash_crit(hashtable,
+ coucal_item *const item = &hashtable->stash.items[i];
+ const size_t pos1 = coucal_hash_to_pos(hashtable, item->hashes.hash1);
+ const size_t pos2 = coucal_hash_to_pos(hashtable, item->hashes.hash2);
+ coucal_crit(hashtable,
"stash[%u]: key='%s' value='%s' pos1=%d pos2=%d hash1=%04x hash2=%04x",
(int) i,
hashtable->custom.print.key(hashtable->custom.print.arg, item->name),
hashtable->custom.print.value(hashtable->custom.print.arg, item->value),
(int) pos1, (int) pos2,
item->hashes.hash1, item->hashes.hash2);
- if (!inthash_is_free(hashtable, pos1)) {
- inthash_item *const item = &hashtable->items[pos1];
- const size_t pos1 = inthash_hash_to_pos(hashtable, item->hashes.hash1);
- const size_t pos2 = inthash_hash_to_pos(hashtable, item->hashes.hash2);
- inthash_crit(hashtable,
+ if (!coucal_is_free(hashtable, pos1)) {
+ coucal_item *const item = &hashtable->items[pos1];
+ const size_t pos1 = coucal_hash_to_pos(hashtable, item->hashes.hash1);
+ const size_t pos2 = coucal_hash_to_pos(hashtable, item->hashes.hash2);
+ coucal_crit(hashtable,
"\t.. collisionning with key='%s' value='%s' pos1=%d pos2=%d hash1=%04x hash2=%04x",
hashtable->custom.print.key(hashtable->custom.print.arg, item->name),
hashtable->custom.print.value(hashtable->custom.print.arg, item->value),
(int) pos1, (int) pos2,
item->hashes.hash1, item->hashes.hash2);
} else {
- inthash_crit(hashtable, "\t.. collisionning with a free slot (%d)!", (int) pos1);
+ coucal_crit(hashtable, "\t.. collisionning with a free slot (%d)!", (int) pos1);
}
- if (!inthash_is_free(hashtable, pos2)) {
- inthash_item *const item = &hashtable->items[pos2];
- const size_t pos1 = inthash_hash_to_pos(hashtable, item->hashes.hash1);
- const size_t pos2 = inthash_hash_to_pos(hashtable, item->hashes.hash2);
- inthash_crit(hashtable,
+ if (!coucal_is_free(hashtable, pos2)) {
+ coucal_item *const item = &hashtable->items[pos2];
+ const size_t pos1 = coucal_hash_to_pos(hashtable, item->hashes.hash1);
+ const size_t pos2 = coucal_hash_to_pos(hashtable, item->hashes.hash2);
+ coucal_crit(hashtable,
"\t.. collisionning with key='%s' value='%s' pos1=%d pos2=%d hash1=%04x hash2=%04x",
hashtable->custom.print.key(hashtable->custom.print.arg, item->name),
hashtable->custom.print.value(hashtable->custom.print.arg, item->value),
(int) pos1, (int) pos2,
item->hashes.hash1, item->hashes.hash2);
} else {
- inthash_crit(hashtable, "\t.. collisionning with a free slot (%d)!", (int) pos2);
+ coucal_crit(hashtable, "\t.. collisionning with a free slot (%d)!", (int) pos2);
}
}
- //struct_inthash_enum e = inthash_enum_new(hashtable);
- //while((item = inthash_enum_next(&e)) != NULL) {
- // inthash_crit(hashtable, "element key='%s' value='%s' hash1=%04x hash2=%04x",
+ //struct_coucal_enum e = coucal_enum_new(hashtable);
+ //while((item = coucal_enum_next(&e)) != NULL) {
+ // coucal_crit(hashtable, "element key='%s' value='%s' hash1=%04x hash2=%04x",
// hashtable->custom.print.key(hashtable->custom.print.arg, item->name),
// hashtable->custom.print.value(hashtable->custom.print.arg, item->value.ptr),
// item->hashes.hash1, item->hashes.hash2);
@@ -963,18 +963,18 @@ static int inthash_add_item_(inthash hashtable, inthash_item item) {
/* we are doomed. hopefully the probability is lower than being killed
by a wandering radioactive monkey */
- inthash_log_stats(hashtable);
- inthash_assert(hashtable, ! "hashtable internal error: cuckoo/stash collision");
+ coucal_log_stats(hashtable);
+ coucal_assert(hashtable, ! "hashtable internal error: cuckoo/stash collision");
/* not reachable code */
return -1;
}
}
-int inthash_write_value(inthash hashtable, inthash_key_const name,
- inthash_value_const value) {
+int coucal_write_value(coucal hashtable, coucal_key_const name,
+ coucal_value_const value) {
/* replace of add item */
- const int ret = inthash_write_value_(hashtable, name, value);
+ const int ret = coucal_write_value_(hashtable, name, value);
/* added ? */
if (ret) {
@@ -995,7 +995,7 @@ int inthash_write_value(inthash hashtable, inthash_key_const name,
/* size before */
const size_t prev_power = hashtable->lg_size;
const size_t prev_size = half_size * 2;
- const size_t prev_alloc_size = prev_size*sizeof(inthash_item);
+ const size_t prev_alloc_size = prev_size*sizeof(coucal_item);
/* size after doubling it */
const size_t alloc_size = prev_alloc_size * 2;
@@ -1004,7 +1004,7 @@ int inthash_write_value(inthash hashtable, inthash_key_const name,
if (hashtable->stash.size >= half_stash_size
&& half_size > POW2(16)
&& hashtable->used < half_size / 4) {
- inthash_warning(hashtable,
+ coucal_warning(hashtable,
"stash size still full despite %"UINT_64_FORMAT
" elements used out of %"UINT_64_FORMAT,
(uint64_t) hashtable->used, (uint64_t) half_size*2);
@@ -1016,13 +1016,13 @@ int inthash_write_value(inthash hashtable, inthash_key_const name,
/* realloc */
hashtable->lg_size++;
hashtable->items =
- (inthash_item *) realloc(hashtable->items, alloc_size);
+ (coucal_item *) realloc(hashtable->items, alloc_size);
if (hashtable->items == NULL) {
- inthash_crit(hashtable,
+ coucal_crit(hashtable,
"** hashtable allocation error: "
"could not allocate %"UINT_64_FORMAT" bytes",
(uint64_t) alloc_size);
- inthash_assert(hashtable, ! "hashtable allocation error");
+ coucal_assert(hashtable, ! "hashtable allocation error");
}
/* clear upper half */
@@ -1030,35 +1030,35 @@ int inthash_write_value(inthash hashtable, inthash_key_const name,
/* relocate lower half items when needed */
for(i = 0 ; i < prev_size ; i++) {
- if (!inthash_is_free(hashtable, i)) {
- const inthash_hashkeys *const hashes = &hashtable->items[i].hashes;
+ if (!coucal_is_free(hashtable, i)) {
+ const coucal_hashkeys *const hashes = &hashtable->items[i].hashes;
/* currently at old position 1 */
- if (inthash_hash_to_pos_(prev_power, hashes->hash1) == i) {
- const size_t pos = inthash_hash_to_pos(hashtable, hashes->hash1);
+ if (coucal_hash_to_pos_(prev_power, hashes->hash1) == i) {
+ const size_t pos = coucal_hash_to_pos(hashtable, hashes->hash1);
/* no more the expected position */
if (pos != i) {
- inthash_assert(hashtable, pos >= prev_size);
+ coucal_assert(hashtable, pos >= prev_size);
hashtable->items[pos] = hashtable->items[i];
memset(&hashtable->items[i], 0, sizeof(hashtable->items[i]));
}
}
- else if (inthash_hash_to_pos_(prev_power, hashes->hash2) == i) {
- const size_t pos = inthash_hash_to_pos(hashtable, hashes->hash2);
+ else if (coucal_hash_to_pos_(prev_power, hashes->hash2) == i) {
+ const size_t pos = coucal_hash_to_pos(hashtable, hashes->hash2);
/* no more the expected position */
if (pos != i) {
- inthash_assert(hashtable, pos >= prev_size);
+ coucal_assert(hashtable, pos >= prev_size);
hashtable->items[pos] = hashtable->items[i];
memset(&hashtable->items[i], 0, sizeof(hashtable->items[i]));
}
}
else {
- inthash_assert(hashtable, ! "hashtable unexpected internal error (bad position)");
+ coucal_assert(hashtable, ! "hashtable unexpected internal error (bad position)");
}
}
}
- inthash_debug(hashtable,
+ coucal_debug(hashtable,
"expanded hashtable to %"UINT_64_FORMAT" elements",
(uint64_t) POW2(hashtable->lg_size));
@@ -1068,26 +1068,26 @@ int inthash_write_value(inthash hashtable, inthash_key_const name,
size_t i;
/* backup stash and reset it */
- inthash_item stash[STASH_SIZE];
+ coucal_item stash[STASH_SIZE];
memcpy(&stash, hashtable->stash.items, sizeof(hashtable->stash.items));
hashtable->stash.size = 0;
/* insert all items */
for(i = 0 ; i < old_size ; i++) {
- const int ret = inthash_add_item_(hashtable, stash[i]);
+ const int ret = coucal_add_item_(hashtable, stash[i]);
if (ret == 0) {
- inthash_assert(hashtable, ! "hashtable duplicate key when merging the stash");
+ coucal_assert(hashtable, ! "hashtable duplicate key when merging the stash");
}
}
/* logging */
- inthash_assert(hashtable, hashtable->stash.size <= old_size);
+ coucal_assert(hashtable, hashtable->stash.size <= old_size);
if (hashtable->stash.size < old_size) {
- inthash_debug(hashtable, "reduced stash size from %"UINT_64_FORMAT" "
+ coucal_debug(hashtable, "reduced stash size from %"UINT_64_FORMAT" "
"to %"UINT_64_FORMAT,
(uint64_t) old_size, (uint64_t) hashtable->stash.size);
} else {
- inthash_trace(hashtable, "stash has still %"UINT_64_FORMAT" elements",
+ coucal_trace(hashtable, "stash has still %"UINT_64_FORMAT" elements",
(uint64_t) hashtable->stash.size);
}
}
@@ -1098,37 +1098,37 @@ int inthash_write_value(inthash hashtable, inthash_key_const name,
return ret;
}
-void inthash_add(inthash hashtable, inthash_key_const name, intptr_t intvalue) {
- inthash_value value = INTHASH_VALUE_NULL;
+void coucal_add(coucal hashtable, coucal_key_const name, intptr_t intvalue) {
+ coucal_value value = INTHASH_VALUE_NULL;
memset(&value, 0, sizeof(value));
value.intg = intvalue;
- inthash_write_value(hashtable, name, value);
+ coucal_write_value(hashtable, name, value);
}
-int inthash_read(inthash hashtable, inthash_key_const name, intptr_t * intvalue) {
- inthash_value value = INTHASH_VALUE_NULL;
+int coucal_read(coucal hashtable, coucal_key_const name, intptr_t * intvalue) {
+ coucal_value value = INTHASH_VALUE_NULL;
int ret =
- inthash_read_value(hashtable, name, (intvalue != NULL) ? &value : NULL);
+ coucal_read_value(hashtable, name, (intvalue != NULL) ? &value : NULL);
if (intvalue != NULL)
*intvalue = value.intg;
return ret;
}
-static inthash_value* inthash_read_value_(inthash hashtable,
- inthash_key_const name) {
- const inthash_hashkeys hashes = inthash_calc_hashes(hashtable, name);
+static coucal_value* coucal_read_value_(coucal hashtable,
+ coucal_key_const name) {
+ const coucal_hashkeys hashes = coucal_calc_hashes(hashtable, name);
size_t pos;
/* found at position 1 ? */
- pos = inthash_hash_to_pos(hashtable, hashes.hash1);
- if (inthash_matches(hashtable, pos, name, &hashes)) {
+ pos = coucal_hash_to_pos(hashtable, hashes.hash1);
+ if (coucal_matches(hashtable, pos, name, &hashes)) {
return &hashtable->items[pos].value;
}
/* found at position 2 ? */
- pos = inthash_hash_to_pos(hashtable, hashes.hash2);
- if (inthash_matches(hashtable, pos, name, &hashes)) {
+ pos = coucal_hash_to_pos(hashtable, hashes.hash2);
+ if (coucal_matches(hashtable, pos, name, &hashes)) {
return &hashtable->items[pos].value;
}
@@ -1136,7 +1136,7 @@ static inthash_value* inthash_read_value_(inthash hashtable,
if (hashtable->stash.size != 0) {
size_t i;
for(i = 0 ; i < hashtable->stash.size ; i++) {
- if (inthash_matches_(hashtable, &hashtable->stash.items[i], name,
+ if (coucal_matches_(hashtable, &hashtable->stash.items[i], name,
&hashes)) {
return &hashtable->stash.items[i].value;
}
@@ -1147,9 +1147,9 @@ static inthash_value* inthash_read_value_(inthash hashtable,
return NULL;
}
-int inthash_read_value(inthash hashtable, inthash_key_const name,
- inthash_value * pvalue) {
- inthash_value* const value = inthash_read_value_(hashtable, name);
+int coucal_read_value(coucal hashtable, coucal_key_const name,
+ coucal_value * pvalue) {
+ coucal_value* const value = coucal_read_value_(hashtable, name);
if (value != NULL) {
if (pvalue != NULL) {
*pvalue = *value;
@@ -1159,48 +1159,48 @@ int inthash_read_value(inthash hashtable, inthash_key_const name,
return 0;
}
-static size_t inthash_inc_(inthash hashtable, inthash_key_const name,
- size_t inc) {
- inthash_value* const value = inthash_read_value_(hashtable, name);
+static size_t coucal_inc_(coucal hashtable, coucal_key_const name,
+ size_t inc) {
+ coucal_value* const value = coucal_read_value_(hashtable, name);
if (value != NULL) {
value->uintg += inc;
return value->uintg;
} else {
/* create a new value */
- const int ret = inthash_write(hashtable, name, inc);
- inthash_assert(hashtable, ret);
+ const int ret = coucal_write(hashtable, name, inc);
+ coucal_assert(hashtable, ret);
return inc;
}
}
-int inthash_inc(inthash hashtable, inthash_key_const name) {
- return (int) inthash_inc_(hashtable, name, 1);
+int coucal_inc(coucal hashtable, coucal_key_const name) {
+ return (int) coucal_inc_(hashtable, name, 1);
}
-int inthash_dec(inthash hashtable, inthash_key_const name) {
- return (int) inthash_inc_(hashtable, name, (size_t) -1);
+int coucal_dec(coucal hashtable, coucal_key_const name) {
+ return (int) coucal_inc_(hashtable, name, (size_t) -1);
}
-int inthash_exists(inthash hashtable, inthash_key_const name) {
- return inthash_read_value(hashtable, name, NULL);
+int coucal_exists(coucal hashtable, coucal_key_const name) {
+ return coucal_read_value(hashtable, name, NULL);
}
-static int inthash_remove_(inthash hashtable, inthash_key_const name,
- const inthash_hashkeys *hashes, size_t *removed) {
+static int coucal_remove_(coucal hashtable, coucal_key_const name,
+ const coucal_hashkeys *hashes, size_t *removed) {
size_t pos;
/* found at position 1 ? */
- pos = inthash_hash_to_pos(hashtable, hashes->hash1);
- if (inthash_matches(hashtable, pos, name, hashes)) {
- inthash_del_item(hashtable, &hashtable->items[pos]);
+ pos = coucal_hash_to_pos(hashtable, hashes->hash1);
+ if (coucal_matches(hashtable, pos, name, hashes)) {
+ coucal_del_item(hashtable, &hashtable->items[pos]);
*removed = pos;
return 1;
}
/* found at position 2 ? */
- pos = inthash_hash_to_pos(hashtable, hashes->hash2);
- if (inthash_matches(hashtable, pos, name, hashes)) {
- inthash_del_item(hashtable, &hashtable->items[pos]);
+ pos = coucal_hash_to_pos(hashtable, hashes->hash2);
+ if (coucal_matches(hashtable, pos, name, hashes)) {
+ coucal_del_item(hashtable, &hashtable->items[pos]);
*removed = pos;
return 1;
}
@@ -1209,15 +1209,15 @@ static int inthash_remove_(inthash hashtable, inthash_key_const name,
if (hashtable->stash.size != 0) {
size_t i;
for(i = 0 ; i < hashtable->stash.size ; i++) {
- if (inthash_matches_(hashtable, &hashtable->stash.items[i], name,
+ if (coucal_matches_(hashtable, &hashtable->stash.items[i], name,
hashes)) {
- inthash_del_item(hashtable, &hashtable->stash.items[i]);
+ coucal_del_item(hashtable, &hashtable->stash.items[i]);
for( ; i + 1 < hashtable->stash.size ; i++) {
hashtable->stash.items[i] = hashtable->stash.items[i + 1];
}
hashtable->stash.size--;
*removed = (size_t) -1;
- inthash_debug(hashtable, "debug:deleted item in stash (%d entries)",
+ coucal_debug(hashtable, "debug:deleted item in stash (%d entries)",
(int) hashtable->stash.size);
return 1;
}
@@ -1228,14 +1228,14 @@ static int inthash_remove_(inthash hashtable, inthash_key_const name,
return 0;
}
-int inthash_remove(inthash hashtable, inthash_key_const name) {
- const inthash_hashkeys hashes = inthash_calc_hashes(hashtable, name);
+int coucal_remove(coucal hashtable, coucal_key_const name) {
+ const coucal_hashkeys hashes = coucal_calc_hashes(hashtable, name);
size_t removed;
- const int ret = inthash_remove_(hashtable, name, &hashes, &removed);
+ const int ret = coucal_remove_(hashtable, name, &hashes, &removed);
if (ret) {
/* item was removed: decrease count */
- inthash_assert(hashtable, hashtable->used != 0);
+ coucal_assert(hashtable, hashtable->used != 0);
hashtable->used--;
/* can we place stash entry back to the table ? */
@@ -1243,9 +1243,9 @@ int inthash_remove(inthash hashtable, inthash_key_const name) {
size_t i;
for(i = 0 ; i < hashtable->stash.size ; i++) {
const size_t pos1 =
- inthash_hash_to_pos(hashtable, hashtable->stash.items[i].hashes.hash1);
+ coucal_hash_to_pos(hashtable, hashtable->stash.items[i].hashes.hash1);
const size_t pos2 =
- inthash_hash_to_pos(hashtable, hashtable->stash.items[i].hashes.hash2);
+ coucal_hash_to_pos(hashtable, hashtable->stash.items[i].hashes.hash2);
if (pos1 == removed || pos2 == removed) {
if (pos1 == removed) {
hashtable->items[pos1] = hashtable->stash.items[i];
@@ -1256,7 +1256,7 @@ int inthash_remove(inthash hashtable, inthash_key_const name) {
hashtable->stash.items[i] = hashtable->stash.items[i + 1];
}
hashtable->stash.size--;
- inthash_debug(hashtable, "debug:moved item from stash (%d entries)",
+ coucal_debug(hashtable, "debug:moved item from stash (%d entries)",
(int) hashtable->stash.size);
break;
}
@@ -1267,24 +1267,24 @@ int inthash_remove(inthash hashtable, inthash_key_const name) {
return ret;
}
-int inthash_readptr(inthash hashtable, inthash_key_const name, intptr_t * value) {
+int coucal_readptr(coucal hashtable, coucal_key_const name, intptr_t * value) {
int ret;
*value = 0;
- ret = inthash_read(hashtable, name, value);
+ ret = coucal_read(hashtable, name, value);
if (*value == 0)
ret = 0;
return ret;
}
-inthash inthash_new(size_t initial_size) {
- inthash hashtable = (inthash) calloc(1, sizeof(struct_inthash));
+coucal coucal_new(size_t initial_size) {
+ coucal hashtable = (coucal) calloc(1, sizeof(struct_coucal));
if (hashtable) {
size_t size;
for(size = MIN_LG_SIZE ; POW2(size) < initial_size ; size++) ;
if ((hashtable->items =
- (inthash_item *) calloc(POW2(size), sizeof(inthash_item)))) {
+ (coucal_item *) calloc(POW2(size), sizeof(coucal_item)))) {
hashtable->lg_size = size;
}
hashtable->used = 0;
@@ -1319,14 +1319,14 @@ inthash inthash_new(size_t initial_size) {
return hashtable;
}
-int inthash_created(inthash hashtable) {
+int coucal_created(coucal hashtable) {
return hashtable != NULL && hashtable->items != NULL;
}
-void inthash_value_is_malloc(inthash hashtable, int flag) {
+void coucal_value_is_malloc(coucal hashtable, int flag) {
if (flag) {
if (hashtable->custom.value.free == NULL) {
- hashtable->custom.value.free = inthash_default_free_handler;
+ hashtable->custom.value.free = coucal_default_free_handler;
hashtable->custom.value.arg = NULL;
}
} else {
@@ -1335,25 +1335,25 @@ void inthash_value_is_malloc(inthash hashtable, int flag) {
}
}
-void inthash_set_name(inthash hashtable, inthash_key_const name) {
+void coucal_set_name(coucal hashtable, coucal_key_const name) {
hashtable->custom.error.name = name;
}
-void inthash_value_set_value_handler(inthash hashtable,
- t_inthash_value_freehandler free,
- inthash_opaque arg) {
+void coucal_value_set_value_handler(coucal hashtable,
+ t_coucal_value_freehandler free,
+ coucal_opaque arg) {
hashtable->custom.value.free = free;
hashtable->custom.value.arg = arg;
}
-void inthash_value_set_key_handler(inthash hashtable,
- t_inthash_duphandler dup,
- t_inthash_key_freehandler free,
- t_inthash_hasheshandler hash,
- t_inthash_cmphandler equals,
- inthash_opaque arg) {
+void coucal_value_set_key_handler(coucal hashtable,
+ t_coucal_duphandler dup,
+ t_coucal_key_freehandler free,
+ t_coucal_hasheshandler hash,
+ t_coucal_cmphandler equals,
+ coucal_opaque arg) {
/* dup and free must be consistent */
- inthash_assert(hashtable, ( dup == NULL ) == ( free == NULL ) );
+ coucal_assert(hashtable, ( dup == NULL ) == ( free == NULL ) );
hashtable->custom.key.dup = dup;
hashtable->custom.key.free = free;
hashtable->custom.key.hash = hash;
@@ -1361,42 +1361,42 @@ void inthash_value_set_key_handler(inthash hashtable,
hashtable->custom.key.arg = arg;
}
-void inthash_set_assert_handler(inthash hashtable,
- t_inthash_loghandler log,
- t_inthash_asserthandler fatal,
- inthash_opaque arg) {
+void coucal_set_assert_handler(coucal hashtable,
+ t_coucal_loghandler log,
+ t_coucal_asserthandler fatal,
+ coucal_opaque arg) {
hashtable->custom.error.log = log;
hashtable->custom.error.fatal = fatal;
hashtable->custom.error.arg = arg;
}
-void inthash_set_print_handler(inthash hashtable,
- t_inthash_printkeyhandler key,
- t_inthash_printvaluehandler value,
- inthash_opaque arg) {
+void coucal_set_print_handler(coucal hashtable,
+ t_coucal_printkeyhandler key,
+ t_coucal_printvaluehandler value,
+ coucal_opaque arg) {
hashtable->custom.print.key = key;
hashtable->custom.print.value = value;
hashtable->custom.print.arg = arg;
}
-size_t inthash_nitems(inthash hashtable) {
+size_t coucal_nitems(coucal hashtable) {
if (hashtable != NULL)
return hashtable->used;
return 0;
}
-size_t inthash_memory_size(inthash hashtable) {
- const size_t size_struct = sizeof(struct_inthash);
- const size_t hash_size = POW2(hashtable->lg_size)*sizeof(inthash_item);
+size_t coucal_memory_size(coucal hashtable) {
+ const size_t size_struct = sizeof(struct_coucal);
+ const size_t hash_size = POW2(hashtable->lg_size)*sizeof(coucal_item);
const size_t pool_size = hashtable->pool.capacity*sizeof(char);
return size_struct + hash_size + pool_size;
}
-void inthash_delete(inthash *phashtable) {
+void coucal_delete(coucal *phashtable) {
if (phashtable != NULL) {
- inthash hashtable = *phashtable;
+ coucal hashtable = *phashtable;
if (hashtable != NULL) {
- inthash_log_stats(hashtable);
+ coucal_log_stats(hashtable);
if (hashtable->items != NULL) {
/* we need to delete values */
const size_t hash_size = POW2(hashtable->lg_size);
@@ -1404,14 +1404,14 @@ void inthash_delete(inthash *phashtable) {
/* wipe hashtable values (not names) */
for(i = 0 ; i < hash_size ; i++) {
- if (!inthash_is_free(hashtable, i)) {
- inthash_del_value(hashtable, i);
+ if (!coucal_is_free(hashtable, i)) {
+ coucal_del_value(hashtable, i);
}
}
/* wipe auxiliary stash values (not names) if any */
for(i = 0 ; i < hashtable->stash.size ; i++) {
- inthash_del_value_(hashtable, &hashtable->stash.items[i].value);
+ coucal_del_value_(hashtable, &hashtable->stash.items[i].value);
}
}
/* wipe top-level */
@@ -1429,28 +1429,28 @@ void inthash_delete(inthash *phashtable) {
/* Enumerator */
-struct_inthash_enum inthash_enum_new(inthash hashtable) {
- struct_inthash_enum e;
+struct_coucal_enum coucal_enum_new(coucal hashtable) {
+ struct_coucal_enum e;
e.index = 0;
e.table = hashtable;
return e;
}
-inthash_item *inthash_enum_next(struct_inthash_enum * e) {
+coucal_item *coucal_enum_next(struct_coucal_enum * e) {
const size_t hash_size = POW2(e->table->lg_size);
for( ; e->index < hash_size
- && inthash_is_free(e->table, e->index) ; e->index++) ;
+ && coucal_is_free(e->table, e->index) ; e->index++) ;
/* enumerate all table */
if (e->index < hash_size) {
- inthash_item *const next = &e->table->items[e->index];
+ coucal_item *const next = &e->table->items[e->index];
e->index++;
return next;
}
/* enumerate stash if present */
else if (e->index < hash_size + e->table->stash.size) {
const size_t index = e->index - hash_size;
- inthash_item *const next = &e->table->stash.items[index];
+ coucal_item *const next = &e->table->stash.items[index];
e->index++;
return next;
}
@@ -1460,8 +1460,8 @@ inthash_item *inthash_enum_next(struct_inthash_enum * e) {
}
}
-void inthash_set_global_assert_handler(t_inthash_loghandler log,
- t_inthash_asserthandler fatal) {
+void coucal_set_global_assert_handler(t_coucal_loghandler log,
+ t_coucal_asserthandler fatal) {
global_log_handler = log;
global_assert_handler = fatal;
}
diff --git a/src/coucal.h b/src/coucal.h
index 0b3ae7c..478ef05 100644
--- a/src/coucal.h
+++ b/src/coucal.h
@@ -66,16 +66,16 @@ typedef unsigned __int64 uint64_t;
#include <stdarg.h>
/** Key opaque type. May be a regular 'const char*'. **/
-typedef void* inthash_key;
+typedef void* coucal_key;
/** Key constant (can not be modified) opaque type. **/
-typedef const void* inthash_key_const;
+typedef const void* coucal_key_const;
/** Opaque user-defined pointer. **/
-typedef void* inthash_opaque;
+typedef void* coucal_opaque;
/** Value (union of any value). **/
-typedef union inthash_value {
+typedef union coucal_value {
/** Integer value. **/
intptr_t intg;
@@ -84,106 +84,106 @@ typedef union inthash_value {
/** Pointer value. **/
void *ptr;
-} inthash_value;
+} coucal_value;
/** Value constant. **/
-typedef const inthash_value inthash_value_const;
+typedef const coucal_value coucal_value_const;
/** NULL Value. **/
#define INTHASH_VALUE_NULL { 0 }
-#ifndef HTS_DEF_FWSTRUCT_inthash_item
-#define HTS_DEF_FWSTRUCT_inthash_item
-typedef struct inthash_item inthash_item;
+#ifndef HTS_DEF_FWSTRUCT_coucal_item
+#define HTS_DEF_FWSTRUCT_coucal_item
+typedef struct coucal_item coucal_item;
#endif
/** Hash key (32-bit) **/
-typedef uint32_t inthash_hashkey;
+typedef uint32_t coucal_hashkey;
/** Pair of hashes **/
-typedef struct inthash_hashkeys {
- inthash_hashkey hash1;
- inthash_hashkey hash2;
-} inthash_hashkeys;
+typedef struct coucal_hashkeys {
+ coucal_hashkey hash1;
+ coucal_hashkey hash2;
+} coucal_hashkeys;
/** NULL pair of hashes. **/
#define INTHASH_KEYS_NULL { 0, 0 }
/** Item holding a value. **/
-struct inthash_item {
+struct coucal_item {
/** Key. **/
- inthash_key name;
+ coucal_key name;
/** Value. **/
- inthash_value value;
+ coucal_value value;
/** Hashes of the key. **/
- inthash_hashkeys hashes;
+ coucal_hashkeys hashes;
};
/** Log level. **/
-typedef enum inthash_loglevel {
- inthash_log_critical,
- inthash_log_warning,
- inthash_log_info,
- inthash_log_debug,
- inthash_log_trace
-} inthash_loglevel;
+typedef enum coucal_loglevel {
+ coucal_log_critical,
+ coucal_log_warning,
+ coucal_log_info,
+ coucal_log_debug,
+ coucal_log_trace
+} coucal_loglevel;
/** free handler. Only used when values are markes as xxc **/
-typedef void (*t_inthash_key_freehandler)(inthash_opaque arg,
- inthash_key key);
+typedef void (*t_coucal_key_freehandler)(coucal_opaque arg,
+ coucal_key key);
/** Value free handler. Only used when values are markes as xxc **/
-typedef void (*t_inthash_value_freehandler)(inthash_opaque arg,
- inthash_value value);
+typedef void (*t_coucal_value_freehandler)(coucal_opaque arg,
+ coucal_value value);
/** Key dup handler. **/
-typedef inthash_key (*t_inthash_duphandler)(inthash_opaque arg,
- inthash_key_const name);
+typedef coucal_key (*t_coucal_duphandler)(coucal_opaque arg,
+ coucal_key_const name);
/** Key hash computation handler. **/
-typedef inthash_hashkeys (*t_inthash_hasheshandler)(inthash_opaque arg,
- inthash_key_const name);
+typedef coucal_hashkeys (*t_coucal_hasheshandler)(coucal_opaque arg,
+ coucal_key_const name);
/** Hashtable logging handler. **/
-typedef void (*t_inthash_loghandler)(inthash_opaque arg, inthash_loglevel level,
- const char* format, va_list args);
+typedef void (*t_coucal_loghandler)(coucal_opaque arg, coucal_loglevel level,
+ const char* format, va_list args);
/** Hashtable fatal assertion failure. **/
-typedef void (*t_inthash_asserthandler)(inthash_opaque arg, const char* exp,
- const char* file, int line);
+typedef void (*t_coucal_asserthandler)(coucal_opaque arg, const char* exp,
+ const char* file, int line);
/** Key printer (debug) **/
-typedef const char* (*t_inthash_printkeyhandler)(inthash_opaque arg,
- inthash_key_const name);
+typedef const char* (*t_coucal_printkeyhandler)(coucal_opaque arg,
+ coucal_key_const name);
/** Value printer (debug) **/
-typedef const char* (*t_inthash_printvaluehandler)(inthash_opaque arg,
- inthash_value_const value);
+typedef const char* (*t_coucal_printvaluehandler)(coucal_opaque arg,
+ coucal_value_const value);
/**
* Value comparison handler (returns non-zero value if strings are equal).
**/
-typedef int (*t_inthash_cmphandler)(inthash_opaque arg,
- inthash_key_const a,
- inthash_key_const b);
+typedef int (*t_coucal_cmphandler)(coucal_opaque arg,
+ coucal_key_const a,
+ coucal_key_const b);
/** Hashtable (opaque structure). **/
-#ifndef HTS_DEF_FWSTRUCT_struct_inthash
-#define HTS_DEF_FWSTRUCT_struct_inthash
-typedef struct struct_inthash struct_inthash, *inthash;
+#ifndef HTS_DEF_FWSTRUCT_struct_coucal
+#define HTS_DEF_FWSTRUCT_struct_coucal
+typedef struct struct_coucal struct_coucal, *coucal;
#endif
/** Hashtable enumeration (opaque structure). **/
-#ifndef HTS_DEF_FWSTRUCT_struct_inthash_enum
-#define HTS_DEF_FWSTRUCT_struct_inthash_enum
-typedef struct struct_inthash_enum struct_inthash_enum;
+#ifndef HTS_DEF_FWSTRUCT_struct_coucal_enum
+#define HTS_DEF_FWSTRUCT_struct_coucal_enum
+typedef struct struct_coucal_enum struct_coucal_enum;
#endif
/** Enumeration. **/
-struct struct_inthash_enum {
- inthash table;
+struct struct_coucal_enum {
+ coucal table;
size_t index;
};
@@ -195,36 +195,42 @@ extern "C" {
* Create a new hashtable, with initial bucket size of 'size'.
* If size is 0, use the default minimal bucket size.
* Return a non-NULL pointer upon success.
+ *
+ * By default, keys are supposed to be '\0'-terminated strings, which are
+ * duplicated by the library (the passed pointer does not need to be
+ * persistent), and values are opaque pointers (or integers) which are copied
+ * "as is", without further processing. Use coucal_value_set_key_handler()
+ * and coucal_value_set_value_handler() to alter this default behavior.
**/
-inthash inthash_new(size_t size);
+coucal coucal_new(size_t size);
/**
* Was the hashtable successfully created ?
* Return non-zero value if the hashtable is valid.
**/
-int inthash_created(inthash hashtable);
+int coucal_created(coucal hashtable);
/**
* Delete a hashtable, freeing all entries.
**/
-void inthash_delete(inthash * hashtable);
+void coucal_delete(coucal * hashtable);
/**
* Return the number of items in the hashtable.
**/
-size_t inthash_nitems(inthash hashtable);
+size_t coucal_nitems(coucal hashtable);
/**
* Return the memory size taken by the hashtable.
* (This does not take account of the possible memory taken by values)
**/
-size_t inthash_memory_size(inthash hashtable);
+size_t coucal_memory_size(coucal hashtable);
/**
- * If 'flag' is non-zero, calls inthash_value_set_value_handler() with
+ * If 'flag' is non-zero, calls coucal_value_set_value_handler() with
* default system free() handler function, otherwise, free the value handlers.
**/
-void inthash_value_is_malloc(inthash hashtable, int flag);
+void coucal_value_is_malloc(coucal hashtable, int flag);
/**
* Set handlers for values.
@@ -233,9 +239,9 @@ void inthash_value_is_malloc(inthash hashtable, int flag);
* arg: opaque custom argument to be used by functions.
* Handler(s) MUST NOT be changed once elements have been added.
**/
-void inthash_value_set_value_handler(inthash hashtable,
- t_inthash_value_freehandler free,
- inthash_opaque arg);
+void coucal_value_set_value_handler(coucal hashtable,
+ t_coucal_value_freehandler free,
+ coucal_opaque arg);
/**
* Set handlers for keys.
@@ -248,22 +254,22 @@ void inthash_value_set_value_handler(inthash hashtable,
* arg: opaque custom argument to be used by functions.
* Handler(s) MUST NOT be changed once elements have been added.
**/
-void inthash_value_set_key_handler(inthash hashtable,
- t_inthash_duphandler dup,
- t_inthash_key_freehandler free,
- t_inthash_hasheshandler hash,
- t_inthash_cmphandler equals,
- inthash_opaque arg);
+void coucal_value_set_key_handler(coucal hashtable,
+ t_coucal_duphandler dup,
+ t_coucal_key_freehandler free,
+ t_coucal_hasheshandler hash,
+ t_coucal_cmphandler equals,
+ coucal_opaque arg);
/**
* Set assertion failure handler.
* log: handler called upon serious programming error
* fatal: handler called upon serious programming error
**/
-void inthash_set_assert_handler(inthash hashtable,
- t_inthash_loghandler log,
- t_inthash_asserthandler fatal,
- inthash_opaque arg);
+void coucal_set_assert_handler(coucal hashtable,
+ t_coucal_loghandler log,
+ t_coucal_asserthandler fatal,
+ coucal_opaque arg);
/**
* Set pretty print loggers (debug). Both handlers must return a string
@@ -272,117 +278,118 @@ void inthash_set_assert_handler(inthash hashtable,
* name: handler called to print the string representation of the name
* value: handler called to print the string representation of the value
**/
-void inthash_set_print_handler(inthash hashtable,
- t_inthash_printkeyhandler key,
- t_inthash_printvaluehandler value,
- inthash_opaque arg);
+void coucal_set_print_handler(coucal hashtable,
+ t_coucal_printkeyhandler key,
+ t_coucal_printvaluehandler value,
+ coucal_opaque arg);
/**
* Set the hashtable name, for degugging purpose.
* name: the hashtable name (ASCII or UTF-8)
*/
-void inthash_set_name(inthash hashtable, inthash_key_const name);
+void coucal_set_name(coucal hashtable, coucal_key_const name);
/**
* Get the hashtable name, for degugging purpose.
* Return NULL if no name was defined.
**/
-const char* inthash_get_name(inthash hashtable);
+const char* coucal_get_name(coucal hashtable);
/**
* Read an integer entry from the hashtable.
* Return non-zero value upon success and sets intvalue.
**/
-int inthash_read(inthash hashtable, inthash_key_const name, intptr_t * intvalue);
+int coucal_read(coucal hashtable, coucal_key_const name, intptr_t * intvalue);
/**
- * Same as inthash_read(), but return 0 is the value was zero.
+ * Same as coucal_read(), but return 0 is the value was zero.
**/
-int inthash_readptr(inthash hashtable, inthash_key_const name, intptr_t * intvalue);
+int coucal_readptr(coucal hashtable, coucal_key_const name, intptr_t * intvalue);
/**
* Return non-zero value if the given entry exists.
**/
-int inthash_exists(inthash hashtable, inthash_key_const name);
+int coucal_exists(coucal hashtable, coucal_key_const name);
/**
* Read an entry from the hashtable.
* Return non-zero value upon success and sets value.
**/
-int inthash_read_value(inthash hashtable, inthash_key_const name,
- inthash_value *value);
+int coucal_read_value(coucal hashtable, coucal_key_const name,
+ coucal_value *value);
/**
* Write an entry to the hashtable.
* Return non-zero value if the entry was added, zero if it was replaced.
**/
-int inthash_write_value(inthash hashtable, inthash_key_const name,
- inthash_value_const value);
+int coucal_write_value(coucal hashtable, coucal_key_const name,
+ coucal_value_const value);
+
/**
* Read a pointer entry from the hashtable.
* Return non-zero value upon success and sets value.
**/
-int inthash_read_pvoid(inthash hashtable, inthash_key_const name, void **value);
+int coucal_read_pvoid(coucal hashtable, coucal_key_const name, void **value);
/**
* Write a pointer entry to the hashtable.
* Return non-zero value if the entry was added, zero if it was replaced.
**/
-int inthash_write_pvoid(inthash hashtable, inthash_key_const name, void *value);
+int coucal_write_pvoid(coucal hashtable, coucal_key_const name, void *value);
/**
- * Alias to inthash_write_pvoid()
+ * Alias to coucal_write_pvoid()
**/
-void inthash_add_pvoid(inthash hashtable, inthash_key_const name, void *value);
+void coucal_add_pvoid(coucal hashtable, coucal_key_const name, void *value);
/**
* Write an integer entry to the hashtable.
* Return non-zero value if the entry was added, zero if it was replaced.
**/
-int inthash_write(inthash hashtable, inthash_key_const name, intptr_t value);
+int coucal_write(coucal hashtable, coucal_key_const name, intptr_t value);
/**
- * Alias to inthash_write()
+ * Alias to coucal_write()
**/
-void inthash_add(inthash hashtable, inthash_key_const name, intptr_t value);
+void coucal_add(coucal hashtable, coucal_key_const name, intptr_t value);
/**
* Increment an entry value in the hashtable
* (or create a new entry with value 1 if it does not yet exist)
* Return non-zero value if the entry was added, zero if it was changed.
**/
-int inthash_inc(inthash hashtable, inthash_key_const name);
+int coucal_inc(coucal hashtable, coucal_key_const name);
/**
* Decrement an entry value in the hashtable
* (or create a new entry with value -1 if it does not yet exist)
* Return non-zero value if the entry was added, zero if it was changed.
**/
-int inthash_dec(inthash hashtable, inthash_key_const name);
+int coucal_dec(coucal hashtable, coucal_key_const name);
/**
* Remove an entry from the hashtable
* Return non-zero value if the entry was removed, zero otherwise.
**/
-int inthash_remove(inthash hashtable, inthash_key_const name);
+int coucal_remove(coucal hashtable, coucal_key_const name);
/**
* Return a new enumerator.
* Note: deleting entries is safe while enumerating, but adding entries
* lead to undefined enumeration behavior (yet safe).
**/
-struct_inthash_enum inthash_enum_new(inthash hashtable);
+struct_coucal_enum coucal_enum_new(coucal hashtable);
/**
* Enumerate the next entry.
**/
-inthash_item *inthash_enum_next(struct_inthash_enum * e);
+coucal_item *coucal_enum_next(struct_coucal_enum * e);
/**
* Compute a hash, given a string. This is the default function used for
* hashing keys, which are by default strings.
**/
-inthash_hashkeys inthash_hash_string(const char *value);
+coucal_hashkeys coucal_hash_string(const char *value);
/**
* Set default global assertion failure handler.
@@ -393,8 +400,8 @@ inthash_hashkeys inthash_hash_string(const char *value);
* fatal: handler called upon serious programming error (opaque argument
* is the hashtable itself)
**/
-void inthash_set_global_assert_handler(t_inthash_loghandler log,
- t_inthash_asserthandler fatal);
+void coucal_set_global_assert_handler(t_coucal_loghandler log,
+ t_coucal_asserthandler fatal);
#ifdef __cplusplus
}
diff --git a/src/htsback.c b/src/htsback.c
index bae89eb..58e3bf7 100644
--- a/src/htsback.c
+++ b/src/htsback.c
@@ -73,11 +73,11 @@ struct_back *back_new(httrackp *opt, int back_max) {
sback->count = back_max;
sback->lnk = (lien_back *) calloct((back_max + 1), sizeof(lien_back));
- sback->ready = inthash_new(0);
+ sback->ready = coucal_new(0);
hts_set_hash_handler(sback->ready, opt);
- inthash_set_name(sback->ready, "back_new");
+ coucal_set_name(sback->ready, "back_new");
sback->ready_size_bytes = 0;
- inthash_value_is_malloc(sback->ready, 1);
+ coucal_value_is_malloc(sback->ready, 1);
// init
for(i = 0; i < sback->count; i++) {
sback->lnk[i].r.location = sback->lnk[i].location_buffer;
@@ -94,7 +94,7 @@ void back_free(struct_back ** sback) {
(*sback)->lnk = NULL;
}
if ((*sback)->ready != NULL) {
- inthash_delete(&(*sback)->ready);
+ coucal_delete(&(*sback)->ready);
(*sback)->ready_size_bytes = 0;
}
freet(*sback);
@@ -112,10 +112,10 @@ void back_delete_all(httrackp * opt, cache_back * cache, struct_back * sback) {
}
// delete stored slots
if (sback->ready != NULL) {
- struct_inthash_enum e = inthash_enum_new(sback->ready);
- inthash_item *item;
+ struct_coucal_enum e = coucal_enum_new(sback->ready);
+ coucal_item *item;
- while((item = inthash_enum_next(&e))) {
+ while((item = coucal_enum_next(&e))) {
#ifndef HTS_NO_BACK_ON_DISK
const char *filename = (char *) item->value.ptr;
@@ -130,7 +130,7 @@ void back_delete_all(httrackp * opt, cache_back * cache, struct_back * sback) {
#endif
}
/* delete hashtable & content */
- inthash_delete(&sback->ready);
+ coucal_delete(&sback->ready);
sback->ready_size_bytes = 0;
}
}
@@ -182,7 +182,7 @@ static int back_index_ready(httrackp * opt, struct_back * sback, const char *adr
lien_back *const back = sback->lnk;
void *ptr = NULL;
- if (inthash_read_pvoid(sback->ready, sav, &ptr)) {
+ if (coucal_read_pvoid(sback->ready, sav, &ptr)) {
if (!getIndex) { /* don't "pagefault" the entry */
if (ptr != NULL) {
return sback->count; /* (invalid but) positive result */
@@ -228,7 +228,7 @@ static int back_index_ready(httrackp * opt, struct_back * sback, const char *adr
back_clear_entry(itemback); /* delete entry content */
freet(itemback); /* delete item */
itemback = NULL;
- inthash_remove(sback->ready, sav); // delete item
+ coucal_remove(sback->ready, sav); // delete item
sback->ready_size_bytes -= back[q].r.size; /* substract for stats */
back_set_locked(sback, q); /* locked */
return q;
@@ -309,7 +309,7 @@ int back_cleanup_background(httrackp * opt, cache_back * cache,
/* Create file and serialize slot */
if ((fp = filecreate(NULL, filename)) != NULL) {
if (back_serialize(fp, &back[i]) == 0) {
- inthash_add_pvoid(sback->ready, back[i].url_sav, filename);
+ coucal_add_pvoid(sback->ready, back[i].url_sav, filename);
filename = NULL;
sback->ready_size_bytes += back[i].r.size; /* add for stats */
nclean++;
@@ -340,7 +340,7 @@ int back_cleanup_background(httrackp * opt, cache_back * cache,
#else
itemback = calloct(1, sizeof(lien_back));
back_move(&back[i], itemback);
- inthash_add_pvoid(sback->ready, itemback->url_sav, itemback);
+ coucal_add_pvoid(sback->ready, itemback->url_sav, itemback);
nclean++;
#endif
}
@@ -375,10 +375,10 @@ LLint back_incache(const struct_back * sback) {
// stored (ready) slots
#ifdef HTS_NO_BACK_ON_DISK
if (sback->ready != NULL) {
- struct_inthash_enum e = inthash_enum_new(sback->ready);
- inthash_item *item;
+ struct_coucal_enum e = coucal_enum_new(sback->ready);
+ coucal_item *item;
- while((item = inthash_enum_next(&e))) {
+ while((item = coucal_enum_next(&e))) {
lien_back *ritem = (lien_back *) item->value.ptr;
if (ritem->status != -1)
@@ -403,12 +403,12 @@ int back_done_incache(const struct_back * sback) {
// stored (ready) slots
if (sback->ready != NULL) {
#ifndef HTS_NO_BACK_ON_DISK
- n += (int) inthash_nitems(sback->ready);
+ n += (int) coucal_nitems(sback->ready);
#else
- struct_inthash_enum e = inthash_enum_new(sback->ready);
- inthash_item *item;
+ struct_coucal_enum e = coucal_enum_new(sback->ready);
+ coucal_item *item;
- while((item = inthash_enum_next(&e))) {
+ while((item = coucal_enum_next(&e))) {
lien_back *ritem = (lien_back *) item->value.ptr;
if (ritem->status == STATUS_READY)
@@ -1506,7 +1506,7 @@ int back_add(struct_back * sback, httrackp * opt, cache_back * cache, const char
if (cache->cached_tests != NULL) {
intptr_t ptr = 0;
- if (inthash_read(cache->cached_tests,
+ if (coucal_read(cache->cached_tests,
concat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), adr, fil), &ptr)) { // gotcha
if (ptr != 0) {
char *text = (char *) ptr;
@@ -1544,7 +1544,7 @@ int back_add(struct_back * sback, httrackp * opt, cache_back * cache, const char
#if HTS_FAST_CACHE
strcpybuff(buff, adr);
strcatbuff(buff, fil);
- hash_pos_return = inthash_read(cache->hashtable, buff, &hash_pos);
+ hash_pos_return = coucal_read(cache->hashtable, buff, &hash_pos);
#else
buff[0] = '\0';
strcatbuff(buff, "\n");
@@ -3978,10 +3978,10 @@ LLint back_transferred(LLint nb, struct_back * sback) {
#ifndef HTS_NO_BACK_ON_DISK
nb += sback->ready_size_bytes;
#else
- struct_inthash_enum e = inthash_enum_new(sback->ready);
- inthash_item *item;
+ struct_coucal_enum e = coucal_enum_new(sback->ready);
+ coucal_item *item;
- while((item = inthash_enum_next(&e))) {
+ while((item = coucal_enum_next(&e))) {
lien_back *ritem = (lien_back *) item->value.ptr;
if ((ritem->status > 0) && (ritem->status < 99 || ritem->status >= 1000))
diff --git a/src/htscache.c b/src/htscache.c
index 783251a..46d2bb4 100644
--- a/src/htscache.c
+++ b/src/htscache.c
@@ -145,7 +145,7 @@ void cache_mayadd(httrackp * opt, cache_back * cache, htsblk * r,
// we just store statuscode + location (if any)
if (url_save == NULL && r->statuscode / 100 >= 3) {
// cached "fast" header doesn't yet exists
- if (inthash_read
+ if (coucal_read
(cache->cached_tests,
concat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), url_adr, url_fil), NULL) == 0) {
char BIGSTK tempo[HTS_URLMAXSIZE * 2];
@@ -158,7 +158,7 @@ void cache_mayadd(httrackp * opt, cache_back * cache, htsblk * r,
hts_log_print(opt, LOG_DEBUG,
"Cached fast-header response: %s%s is %d",
url_adr, url_fil, (int) r->statuscode);
- inthash_add(cache->cached_tests,
+ coucal_add(cache->cached_tests,
concat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), url_adr, url_fil),
(intptr_t) strdupt(tempo));
}
@@ -646,7 +646,7 @@ static htsblk cache_readex_new(httrackp * opt, cache_back * cache,
strcpybuff(r.location, "");
strcpybuff(buff, adr);
strcatbuff(buff, fil);
- hash_pos_return = inthash_read(cache->hashtable, buff, &hash_pos);
+ hash_pos_return = coucal_read(cache->hashtable, buff, &hash_pos);
/* avoid errors on data entries */
if (adr[0] == '/' && adr[1] == '/' && adr[2] == '[') {
#if HTS_FAST_CACHE
@@ -1029,7 +1029,7 @@ static htsblk cache_readex_old(httrackp * opt, cache_back * cache,
#if HTS_FAST_CACHE
strcpybuff(buff, adr);
strcatbuff(buff, fil);
- hash_pos_return = inthash_read(cache->hashtable, buff, &hash_pos);
+ hash_pos_return = coucal_read(cache->hashtable, buff, &hash_pos);
#else
buff[0] = '\0';
strcatbuff(buff, "\n");
@@ -1349,7 +1349,7 @@ int cache_readdata(cache_back * cache, const char *str1, const char *str2,
strcpybuff(buff, str1);
strcatbuff(buff, str2);
- if (inthash_read(cache->hashtable, buff, &pos)) {
+ if (coucal_read(cache->hashtable, buff, &pos)) {
if (fseek(cache->olddat, (long) ((pos > 0) ? pos : (-pos)), SEEK_SET) ==
0) {
INTsys len;
@@ -1642,9 +1642,9 @@ void cache_init(cache_back * cache, httrackp * opt) {
}
}
if (dataincache)
- inthash_add(cache->hashtable, filenameIndex, pos);
+ coucal_add(cache->hashtable, filenameIndex, pos);
else
- inthash_add(cache->hashtable, filenameIndex, -pos);
+ coucal_add(cache->hashtable, filenameIndex, -pos);
} else {
hts_log_print(opt, LOG_WARNING,
"Corrupted cache meta entry #%d",
@@ -1810,7 +1810,7 @@ void cache_init(cache_back * cache, httrackp * opt) {
/* read position */
a += binput(a, linepos, 200);
sscanf(linepos, "%d", &pos);
- inthash_add(cache->hashtable, line, pos);
+ coucal_add(cache->hashtable, line, pos);
}
}
/* Not needed anymore! */
diff --git a/src/htscore.c b/src/htscore.c
index 5a4871d..2d78638 100644
--- a/src/htscore.c
+++ b/src/htscore.c
@@ -149,8 +149,8 @@ RUN_CALLBACK0(opt, end); \
if (maketrack_fp){ fclose(maketrack_fp); maketrack_fp=NULL; } \
if (opt->accept_cookie) cookie_save(opt->cookie,fconcat(OPT_GET_BUFF(opt),OPT_GET_BUFF_SIZE(opt),StringBuff(opt->path_log),"cookies.txt")); \
if (makeindex_fp) { fclose(makeindex_fp); makeindex_fp=NULL; } \
- if (cache_hashtable) { inthash_delete(&cache_hashtable); } \
- if (cache_tests) { inthash_delete(&cache_tests); } \
+ if (cache_hashtable) { coucal_delete(&cache_hashtable); } \
+ if (cache_tests) { coucal_delete(&cache_tests); } \
if (template_header) { freet(template_header); template_header=NULL; } \
if (template_body) { freet(template_body); template_body=NULL; } \
if (template_footer) { freet(template_footer); template_footer=NULL; } \
@@ -479,8 +479,8 @@ int httpmirror(char *url1, httrackp * opt) {
//
cache_back BIGSTK cache;
robots_wizard BIGSTK robots; // gestion robots.txt
- inthash cache_hashtable = NULL;
- inthash cache_tests = NULL;
+ coucal cache_hashtable = NULL;
+ coucal cache_tests = NULL;
//
char *template_header = NULL, *template_body = NULL, *template_footer = NULL;
@@ -563,8 +563,8 @@ int httpmirror(char *url1, httrackp * opt) {
cache.ptr_ant = cache.ptr_last = 0; // pointeur pour anticiper
// initialiser hash cache
- cache_hashtable = inthash_new(0);
- cache_tests = inthash_new(0);
+ cache_hashtable = coucal_new(0);
+ cache_tests = coucal_new(0);
if (cache_hashtable == NULL || cache_tests == NULL) {
printf("PANIC! : Not enough memory [%d]\n", __LINE__);
filters[0] = NULL; // uniquement a cause du warning de XH_extuninit
@@ -573,9 +573,9 @@ int httpmirror(char *url1, httrackp * opt) {
}
hts_set_hash_handler(cache_hashtable, opt);
hts_set_hash_handler(cache_tests, opt);
- inthash_set_name(cache_hashtable, "cache_hashtable");
- inthash_set_name(cache_tests, "cache_tests");
- inthash_value_is_malloc(cache_tests, 1); /* malloc */
+ coucal_set_name(cache_hashtable, "cache_hashtable");
+ coucal_set_name(cache_tests, "cache_tests");
+ coucal_value_is_malloc(cache_tests, 1); /* malloc */
cache.hashtable = (void *) cache_hashtable; /* copy backcache hash */
cache.cached_tests = (void *) cache_tests; /* copy of cache_tests */
diff --git a/src/htscore.h b/src/htscore.h
index 7f96039..1c35c8a 100644
--- a/src/htscore.h
+++ b/src/htscore.h
@@ -156,7 +156,7 @@ typedef struct struct_back struct_back;
struct struct_back {
lien_back *lnk;
int count;
- inthash ready;
+ coucal ready;
LLint ready_size_bytes;
};
@@ -178,9 +178,9 @@ struct cache_back {
FILE *txt; // liste des fichiers (info)
char lastmodified[256];
// HASH
- inthash hashtable;
+ coucal hashtable;
// HASH for tests (naming subsystem)
- inthash cached_tests;
+ coucal cached_tests;
// fichiers log optionnels
FILE *log;
FILE *errlog;
@@ -203,11 +203,11 @@ struct hash_struct {
/* Links big array reference */
const lien_url *const*const*liens;
/* Savename (case insensitive ; lowercased) */
- inthash sav;
+ coucal sav;
/* Address and path */
- inthash adrfil;
+ coucal adrfil;
/* Former address and path */
- inthash former_adrfil;
+ coucal former_adrfil;
/** Buffers **/
int normalized;
char normfil[HTS_URLMAXSIZE * 2];
diff --git a/src/htscoremain.c b/src/htscoremain.c
index e5af672..2cfeb63 100644
--- a/src/htscoremain.c
+++ b/src/htscoremain.c
@@ -1984,7 +1984,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) {
int found = 0;
char *filter = NULL;
cache_back cache;
- inthash cache_hashtable = inthash_new(0);
+ coucal cache_hashtable = coucal_new(0);
int sendb = 0;
if (isdigit((unsigned char) *(com + 1))) {
@@ -2515,7 +2515,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) {
/* successfully read */
if (count > 0) {
- inthash hashtable = inthash_new(0);
+ coucal hashtable = coucal_new(0);
size_t loop;
for(loop = 0 ; bench[loop].type != DO_END ; loop++) {
size_t i;
@@ -2526,9 +2526,9 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) {
if (bench[loop].type == DO_ADD
|| bench[loop].type == DO_DRY_ADD) {
size_t k;
- result = inthash_write(hashtable, name, (uintptr_t) expected);
+ result = coucal_write(hashtable, name, (uintptr_t) expected);
for(k = 0 ; k < /* stash_size*2 */ 32 ; k++) {
- (void) inthash_write(hashtable, name, (uintptr_t) expected);
+ (void) coucal_write(hashtable, name, (uintptr_t) expected);
}
/* revert logic */
if (bench[loop].type == DO_DRY_ADD) {
@@ -2538,9 +2538,9 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) {
else if (bench[loop].type == DO_DEL
|| bench[loop].type == DO_DRY_DEL) {
size_t k;
- result = inthash_remove(hashtable, name);
+ result = coucal_remove(hashtable, name);
for(k = 0 ; k < /* stash_size*2 */ 32 ; k++) {
- (void) inthash_remove(hashtable, name);
+ (void) coucal_remove(hashtable, name);
}
/* revert logic */
if (bench[loop].type == DO_DRY_DEL) {
@@ -2550,7 +2550,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) {
else if (bench[loop].type == TEST_ADD
|| bench[loop].type == TEST_DEL) {
intptr_t value = -1;
- result = inthash_readptr(hashtable, name, &value);
+ result = coucal_readptr(hashtable, name, &value);
if (bench[loop].type == TEST_ADD && result
&& value != expected) {
fprintf(stderr, "value failed for %s (expected %ld, got %ld)\n",
@@ -2573,7 +2573,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) {
}
}
}
- inthash_delete(&hashtable);
+ coucal_delete(&hashtable);
fprintf(stderr, "all hashtable tests were successful!\n");
} else {
fprintf(stderr, "Malformed number\n");
diff --git a/src/htshash.c b/src/htshash.c
index 5bdeb3e..405fa4a 100644
--- a/src/htshash.c
+++ b/src/htshash.c
@@ -60,47 +60,47 @@ Please visit our Website: http://www.httrack.com
// recherche dans la table selon nom1,nom2 et le no d'enregistrement
/* Key free handler (NOOP) ; addresses are kept */
-static void key_freehandler(void *arg, inthash_key value) {
+static void key_freehandler(void *arg, coucal_key value) {
}
/* Key strdup (pointer copy) */
-static inthash_key key_duphandler(void *arg, inthash_key_const name) {
+static coucal_key key_duphandler(void *arg, coucal_key_const name) {
union {
- inthash_key_const roname;
- inthash_key name;
+ coucal_key_const roname;
+ coucal_key name;
} u;
u.roname = name;
return u.name;
}
/* Key sav hashes are using case-insensitive version */
-static inthash_hashkeys key_sav_hashes(void *arg, inthash_key_const key) {
+static coucal_hashkeys key_sav_hashes(void *arg, coucal_key_const key) {
hash_struct *const hash = (hash_struct*) arg;
convtolower(hash->catbuff, (const char*) key);
- return inthash_hash_string(hash->catbuff);
+ return coucal_hash_string(hash->catbuff);
}
/* Key sav comparison is case-insensitive */
static int key_sav_equals(void *arg,
- inthash_key_const a_,
- inthash_key_const b_) {
+ coucal_key_const a_,
+ coucal_key_const b_) {
const char *const a = (const char*) a_;
const char *const b = (const char*) b_;
return strcasecmp(a, b) == 0;
}
static const char* key_sav_debug_print(void *arg,
- inthash_key_const a) {
+ coucal_key_const a) {
return (const char*) a;
}
-static const char* value_sav_debug_print(void *arg, inthash_value_const a) {
+static const char* value_sav_debug_print(void *arg, coucal_value_const a) {
return (char*) a.ptr;
}
/* Pseudo-key (lien_url structure) hash function */
-static inthash_hashkeys key_adrfil_hashes_generic(void *arg,
- inthash_key_const value,
+static coucal_hashkeys key_adrfil_hashes_generic(void *arg,
+ coucal_key_const value,
const int former) {
hash_struct *const hash = (hash_struct*) arg;
const lien_url*const lien = (const lien_url*) value;
@@ -124,13 +124,13 @@ static inthash_hashkeys key_adrfil_hashes_generic(void *arg,
}
// hash
- return inthash_hash_string(hash->normfil);
+ return coucal_hash_string(hash->normfil);
}
/* Pseudo-key (lien_url structure) comparison function */
static int key_adrfil_equals_generic(void *arg,
- inthash_key_const a_,
- inthash_key_const b_,
+ coucal_key_const a_,
+ coucal_key_const b_,
const int former) {
hash_struct *const hash = (hash_struct*) arg;
const int normalized = hash->normalized;
@@ -171,7 +171,7 @@ static int key_adrfil_equals_generic(void *arg,
}
static const char* key_adrfil_debug_print_(void *arg,
- inthash_key_const a_,
+ coucal_key_const a_,
const int former) {
hash_struct *const hash = (hash_struct*) arg;
const lien_url*const a = (const lien_url*) a_;
@@ -182,62 +182,62 @@ static const char* key_adrfil_debug_print_(void *arg,
}
static const char* key_adrfil_debug_print(void *arg,
- inthash_key_const a_) {
+ coucal_key_const a_) {
return key_adrfil_debug_print_(arg, a_, 0);
}
static const char* key_former_adrfil_debug_print(void *arg,
- inthash_key_const a_) {
+ coucal_key_const a_) {
return key_adrfil_debug_print_(arg, a_, 1);
}
static const char* value_adrfil_debug_print(void *arg,
- inthash_value_const value) {
+ coucal_value_const value) {
hash_struct *const hash = (hash_struct*) arg;
snprintf(hash->normfil2, sizeof(hash->normfil2), "%d", (int) value.intg);
return hash->normfil2;
}
/* "adr"/"fil" lien_url structure members hashing function */
-static inthash_hashkeys key_adrfil_hashes(void *arg, inthash_key_const value_) {
+static coucal_hashkeys key_adrfil_hashes(void *arg, coucal_key_const value_) {
return key_adrfil_hashes_generic(arg, value_, 0);
}
/* "adr"/"fil" lien_url structure members comparison function */
static int key_adrfil_equals(void *arg,
- inthash_key_const a,
- inthash_key_const b) {
+ coucal_key_const a,
+ coucal_key_const b) {
return key_adrfil_equals_generic(arg, a, b, 0);
}
/* "former_adr"/"former_fil" lien_url structure members hashing function */
-static inthash_hashkeys key_former_adrfil_hashes(void *arg, inthash_key_const value_) {
+static coucal_hashkeys key_former_adrfil_hashes(void *arg, coucal_key_const value_) {
return key_adrfil_hashes_generic(arg, value_, 1);
}
/* "former_adr"/"former_fil" lien_url structure members comparison function */
static int key_former_adrfil_equals(void *arg,
- inthash_key_const a,
- inthash_key_const b) {
+ coucal_key_const a,
+ coucal_key_const b) {
return key_adrfil_equals_generic(arg, a, b, 1);
}
void hash_init(httrackp *opt, hash_struct * hash, int normalized) {
- hash->sav = inthash_new(0);
- hash->adrfil = inthash_new(0);
- hash->former_adrfil = inthash_new(0);
+ hash->sav = coucal_new(0);
+ hash->adrfil = coucal_new(0);
+ hash->former_adrfil = coucal_new(0);
hash->normalized = normalized;
hts_set_hash_handler(hash->sav, opt);
hts_set_hash_handler(hash->adrfil, opt);
hts_set_hash_handler(hash->former_adrfil, opt);
- inthash_set_name(hash->sav, "hash->sav");
- inthash_set_name(hash->adrfil, "hash->adrfil");
- inthash_set_name(hash->former_adrfil, "hash->former_adrfil");
+ coucal_set_name(hash->sav, "hash->sav");
+ coucal_set_name(hash->adrfil, "hash->adrfil");
+ coucal_set_name(hash->former_adrfil, "hash->former_adrfil");
/* Case-insensitive comparison ; keys are direct char* filenames */
- inthash_value_set_key_handler(hash->sav,
+ coucal_value_set_key_handler(hash->sav,
key_duphandler,
key_freehandler,
key_sav_hashes,
@@ -246,13 +246,13 @@ void hash_init(httrackp *opt, hash_struct * hash, int normalized) {
/* URL-style comparison ; keys are lien_url structure pointers casted
to char* */
- inthash_value_set_key_handler(hash->adrfil,
+ coucal_value_set_key_handler(hash->adrfil,
key_duphandler,
key_freehandler,
key_adrfil_hashes,
key_adrfil_equals,
hash);
- inthash_value_set_key_handler(hash->former_adrfil,
+ coucal_value_set_key_handler(hash->former_adrfil,
key_duphandler,
key_freehandler,
key_former_adrfil_hashes,
@@ -260,15 +260,15 @@ void hash_init(httrackp *opt, hash_struct * hash, int normalized) {
hash);
/* pretty-printing */
- inthash_set_print_handler(hash->sav,
+ coucal_set_print_handler(hash->sav,
key_sav_debug_print,
value_sav_debug_print,
NULL);
- inthash_set_print_handler(hash->adrfil,
+ coucal_set_print_handler(hash->adrfil,
key_adrfil_debug_print,
value_adrfil_debug_print,
hash);
- inthash_set_print_handler(hash->former_adrfil,
+ coucal_set_print_handler(hash->former_adrfil,
key_former_adrfil_debug_print,
value_adrfil_debug_print,
hash);
@@ -276,9 +276,9 @@ void hash_init(httrackp *opt, hash_struct * hash, int normalized) {
void hash_free(hash_struct *hash) {
if (hash != NULL) {
- inthash_delete(&hash->sav);
- inthash_delete(&hash->adrfil);
- inthash_delete(&hash->former_adrfil);
+ coucal_delete(&hash->sav);
+ coucal_delete(&hash->adrfil);
+ coucal_delete(&hash->former_adrfil);
}
}
@@ -291,7 +291,7 @@ int hash_read(const hash_struct * hash, const char *nom1, const char *nom2,
/* read */
switch(type) {
case HASH_STRUCT_FILENAME:
- if (inthash_read(hash->sav, nom1, &intvalue)) {
+ if (coucal_read(hash->sav, nom1, &intvalue)) {
return (int) intvalue;
} else {
return -1;
@@ -301,7 +301,7 @@ int hash_read(const hash_struct * hash, const char *nom1, const char *nom2,
memset(&lien, 0, sizeof(lien));
lien.adr = key_duphandler(NULL, nom1);
lien.fil = key_duphandler(NULL, nom2);
- if (inthash_read(hash->adrfil, (char*) &lien, &intvalue)) {
+ if (coucal_read(hash->adrfil, (char*) &lien, &intvalue)) {
return (int) intvalue;
} else {
return -1;
@@ -311,7 +311,7 @@ int hash_read(const hash_struct * hash, const char *nom1, const char *nom2,
memset(&lien, 0, sizeof(lien));
lien.former_adr = key_duphandler(NULL, nom1);
lien.former_fil = key_duphandler(NULL, nom2);
- if (inthash_read(hash->former_adrfil, (char*) &lien, &intvalue)) {
+ if (coucal_read(hash->former_adrfil, (char*) &lien, &intvalue)) {
return (int) intvalue;
} else {
return -1;
@@ -327,13 +327,13 @@ int hash_read(const hash_struct * hash, const char *nom1, const char *nom2,
// enregistrement lien lpos dans les 3 tables hash1..3
void hash_write(hash_struct * hash, size_t lpos) {
/* first entry: destination filename (lowercased) */
- inthash_write(hash->sav, (*hash->liens)[lpos]->sav, lpos);
+ coucal_write(hash->sav, (*hash->liens)[lpos]->sav, lpos);
/* second entry: URL address and path */
- inthash_write(hash->adrfil, (*hash->liens)[lpos], lpos);
+ coucal_write(hash->adrfil, (*hash->liens)[lpos], lpos);
/* third entry: URL address and path before redirect */
if ((*hash->liens)[lpos]->former_adr) { // former_adr existe?
- inthash_write(hash->former_adrfil, (*hash->liens)[lpos], lpos);
+ coucal_write(hash->former_adrfil, (*hash->liens)[lpos], lpos);
}
}
diff --git a/src/htsindex.c b/src/htsindex.c
index 8414d4b..2f633fd 100644
--- a/src/htsindex.c
+++ b/src/htsindex.c
@@ -144,7 +144,7 @@ int index_keyword(const char *html_data, LLint size, const char *mime,
//
//int WordIndexSize = 1024;
- inthash WordIndexHash = NULL;
+ coucal WordIndexHash = NULL;
FILE *tmpfp = NULL;
//
@@ -190,7 +190,7 @@ int index_keyword(const char *html_data, LLint size, const char *mime,
// Create hash structure
// Hash tables rulez da world!
- WordIndexHash = inthash_new(0);
+ WordIndexHash = coucal_new(0);
if (!WordIndexHash)
return 0;
@@ -252,7 +252,7 @@ int index_keyword(const char *html_data, LLint size, const char *mime,
/* Store it ? */
if (len >= KEYW_MIN_LEN) {
hts_primindex_words++;
- if (inthash_inc(WordIndexHash, keyword)) { /* added new */
+ if (coucal_inc(WordIndexHash, keyword)) { /* added new */
fprintf(tmpfp, "%s\n", keyword);
}
}
@@ -285,7 +285,7 @@ int index_keyword(const char *html_data, LLint size, const char *mime,
if (strnotempty(line)) {
intptr_t e = 0;
- if (inthash_read(WordIndexHash, line, &e)) {
+ if (coucal_read(WordIndexHash, line, &e)) {
//if (e) {
char BIGSTK savelst[HTS_URLMAXSIZE * 2];
@@ -313,7 +313,7 @@ int index_keyword(const char *html_data, LLint size, const char *mime,
tmpfp = NULL;
// Clear hash table
- inthash_delete(&WordIndexHash);
+ coucal_delete(&WordIndexHash);
#endif
return 1;
}
diff --git a/src/htslib.c b/src/htslib.c
index 76c26fd..b96d4b2 100644
--- a/src/htslib.c
+++ b/src/htslib.c
@@ -5022,25 +5022,25 @@ HTSEXT_API htsErrorCallback hts_get_error_callback(void) {
return htsCallbackErr;
}
-static void default_inthash_asserthandler(void *arg, const char* exp, const char* file, int line) {
+static void default_coucal_asserthandler(void *arg, const char* exp, const char* file, int line) {
abortf_(exp, file, line);
}
-static int get_loglevel_from_inthash(inthash_loglevel level) {
+static int get_loglevel_from_coucal(coucal_loglevel level) {
switch(level) {
- case inthash_log_critical:
+ case coucal_log_critical:
return LOG_PANIC;
break;
- case inthash_log_warning:
+ case coucal_log_warning:
return LOG_WARNING;
break;
- case inthash_log_info:
+ case coucal_log_info:
return LOG_INFO;
break;
- case inthash_log_debug:
+ case coucal_log_debug:
return LOG_DEBUG;
break;
- case inthash_log_trace:
+ case coucal_log_trace:
return LOG_TRACE;
break;
default:
@@ -5050,10 +5050,10 @@ static int get_loglevel_from_inthash(inthash_loglevel level) {
}
/* log to default console */
-static void default_inthash_loghandler(void *arg, inthash_loglevel level,
+static void default_coucal_loghandler(void *arg, coucal_loglevel level,
const char* format, va_list args) {
- if (level <= inthash_log_warning) {
+ if (level <= coucal_log_warning) {
fprintf(stderr, "** warning: ");
}
vfprintf(stderr, format, args);
@@ -5061,23 +5061,23 @@ static void default_inthash_loghandler(void *arg, inthash_loglevel level,
}
/* log to project log */
-static void htsopt_inthash_loghandler(void *arg, inthash_loglevel level,
+static void htsopt_coucal_loghandler(void *arg, coucal_loglevel level,
const char* format, va_list args) {
httrackp *const opt = (httrackp*) arg;
if (opt != NULL && opt->log != NULL) {
- hts_log_vprint(opt, get_loglevel_from_inthash(level),
+ hts_log_vprint(opt, get_loglevel_from_coucal(level),
format, args);
} else {
- default_inthash_loghandler(NULL, level, format, args);
+ default_coucal_loghandler(NULL, level, format, args);
}
}
/* attach hashtable logger to project log */
-void hts_set_hash_handler(inthash hashtable, httrackp *opt) {
+void hts_set_hash_handler(coucal hashtable, httrackp *opt) {
/* Init hashtable default assertion handler. */
- inthash_set_assert_handler(hashtable,
- htsopt_inthash_loghandler,
- default_inthash_asserthandler,
+ coucal_set_assert_handler(hashtable,
+ htsopt_coucal_loghandler,
+ default_coucal_asserthandler,
opt);
}
@@ -5103,8 +5103,8 @@ HTSEXT_API int hts_init(void) {
hts_debug_log_print("entering hts_init()"); /* debug */
/* Init hashtable default assertion handler. */
- inthash_set_global_assert_handler(default_inthash_loghandler,
- default_inthash_asserthandler);
+ coucal_set_global_assert_handler(default_coucal_loghandler,
+ default_coucal_asserthandler);
/* Init threads (lazy init) */
htsthread_init();
diff --git a/src/htslib.h b/src/htslib.h
index aec5803..b10c0f4 100644
--- a/src/htslib.h
+++ b/src/htslib.h
@@ -163,7 +163,7 @@ struct t_dnscache {
void hts_init_htsblk(htsblk * r);
// attach specific project log to hachtable logger
-void hts_set_hash_handler(inthash hashtable, httrackp *opt);
+void hts_set_hash_handler(coucal hashtable, httrackp *opt);
// version
HTSEXT_API const char* hts_version(void);
diff --git a/src/htsopt.h b/src/htsopt.h
index 5c2e35e..cc024c9 100644
--- a/src/htsopt.h
+++ b/src/htsopt.h
@@ -205,9 +205,9 @@ typedef struct htsmutex_s htsmutex_s, *htsmutex;
#endif
/* Hashtables */
-#ifndef HTS_DEF_FWSTRUCT_struct_inthash
-#define HTS_DEF_FWSTRUCT_struct_inthash
-typedef struct struct_inthash struct_inthash, *inthash;
+#ifndef HTS_DEF_FWSTRUCT_struct_coucal
+#define HTS_DEF_FWSTRUCT_struct_coucal
+typedef struct struct_coucal struct_coucal, *coucal;
#endif
/* Structure état du miroir */
diff --git a/src/htsserver.c b/src/htsserver.c
index e9f426c..0ee5907 100644
--- a/src/htsserver.c
+++ b/src/htsserver.c
@@ -71,11 +71,11 @@ Please visit our Website: http://www.httrack.com
#undef HTS_INTERNAL_BYTECODE
int NewLangStrSz = 1024;
-inthash NewLangStr = NULL;
+coucal NewLangStr = NULL;
int NewLangStrKeysSz = 1024;
-inthash NewLangStrKeys = NULL;
+coucal NewLangStrKeys = NULL;
int NewLangListSz = 1024;
-inthash NewLangList = NULL;
+coucal NewLangList = NULL;
/* Language files */
@@ -296,7 +296,7 @@ typedef struct {
} initStrElt;
#define SET_ERROR(err) do { \
- inthash_write(NewLangList, "error", (intptr_t)strdup(err)); \
+ coucal_write(NewLangList, "error", (intptr_t)strdup(err)); \
error_redirect = "/server/error.html"; \
} while(0)
@@ -359,18 +359,18 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
char tmp[32];
sprintf(tmp, "%d", initInt[i].value);
- inthash_write(NewLangList, initInt[i].name, (intptr_t) strdup(tmp));
+ coucal_write(NewLangList, initInt[i].name, (intptr_t) strdup(tmp));
}
for(i = 0; initOn[i]; i++) {
- inthash_write(NewLangList, initOn[i], (intptr_t) strdup("1")); /* "on" */
+ coucal_write(NewLangList, initOn[i], (intptr_t) strdup("1")); /* "on" */
}
for(i = 0; initStr[i].name; i++) {
- inthash_write(NewLangList, initStr[i].name,
+ coucal_write(NewLangList, initStr[i].name,
(intptr_t) strdup(initStr[i].value));
}
strcpybuff(pth, gethomedir());
strcatbuff(pth, "/websites");
- inthash_write(NewLangList, "path", (intptr_t) strdup(pth));
+ coucal_write(NewLangList, "path", (intptr_t) strdup(pth));
}
/* Lock */
@@ -468,15 +468,15 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
char tmp[32];
sprintf(tmp, "%d", commandReturn);
- inthash_write(NewLangList, "commandReturn", (intptr_t) strdup(tmp));
- inthash_write(NewLangList, "commandReturnMsg",
+ coucal_write(NewLangList, "commandReturn", (intptr_t) strdup(tmp));
+ coucal_write(NewLangList, "commandReturnMsg",
(intptr_t) commandReturnMsg);
- inthash_write(NewLangList, "commandReturnCmdl",
+ coucal_write(NewLangList, "commandReturnCmdl",
(intptr_t) commandReturnCmdl);
} else {
- inthash_write(NewLangList, "commandReturn", (intptr_t) NULL);
- inthash_write(NewLangList, "commandReturnMsg", (intptr_t) NULL);
- inthash_write(NewLangList, "commandReturnCmdl", (intptr_t) NULL);
+ coucal_write(NewLangList, "commandReturn", (intptr_t) NULL);
+ coucal_write(NewLangList, "commandReturnMsg", (intptr_t) NULL);
+ coucal_write(NewLangList, "commandReturnCmdl", (intptr_t) NULL);
}
}
@@ -484,8 +484,8 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
{
intptr_t adr = 0;
- if (inthash_readptr(NewLangList, "_sid", &adr)) {
- if (inthash_write
+ if (coucal_readptr(NewLangList, "_sid", &adr)) {
+ if (coucal_write
(NewLangList, "sid", (intptr_t) strdup((char *) adr))) {
}
}
@@ -506,7 +506,7 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
if (strfield2(ua, "on")) /* hack : "on" == 1 */
ua = "1";
unescapehttp(ua, &sua);
- inthash_write(NewLangList, s, (intptr_t) StringAcquire(&sua));
+ coucal_write(NewLangList, s, (intptr_t) StringAcquire(&sua));
s = f + 1;
}
}
@@ -516,8 +516,8 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
intptr_t adr = 0;
intptr_t adr2 = 0;
- if (inthash_readptr(NewLangList, "sid", &adr)) {
- if (inthash_readptr(NewLangList, "_sid", &adr2)) {
+ if (coucal_readptr(NewLangList, "sid", &adr)) {
+ if (coucal_readptr(NewLangList, "_sid", &adr2)) {
if (strcmp((char *) adr, (char *) adr2) != 0) {
meth = 0;
}
@@ -530,40 +530,40 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
int doLoad = 0;
intptr_t adr = 0;
- if (inthash_readptr(NewLangList, "lang", &adr)) {
+ if (coucal_readptr(NewLangList, "lang", &adr)) {
int n = 0;
if (sscanf((char *) adr, "%d", &n) == 1 && n > 0
&& n - 1 != LANG_T(path, -1)) {
LANG_T(path, n - 1);
/* make a backup, because the GUI will override it */
- inthash_write(NewLangList, "lang_",
+ coucal_write(NewLangList, "lang_",
(intptr_t) strdup((char *) adr));
}
}
/* Load existing project settings */
- if (inthash_readptr(NewLangList, "loadprojname", &adr)) {
+ if (coucal_readptr(NewLangList, "loadprojname", &adr)) {
char *pname = (char *) adr;
if (*pname) {
- inthash_write(NewLangList, "projname", (intptr_t) strdup(pname));
+ coucal_write(NewLangList, "projname", (intptr_t) strdup(pname));
}
- inthash_write(NewLangList, "loadprojname", (intptr_t) NULL);
+ coucal_write(NewLangList, "loadprojname", (intptr_t) NULL);
doLoad = 1;
- } else if (inthash_readptr(NewLangList, "loadprojcateg", &adr)) {
+ } else if (coucal_readptr(NewLangList, "loadprojcateg", &adr)) {
char *pname = (char *) adr;
if (*pname) {
- inthash_write(NewLangList, "projcateg", (intptr_t) strdup(pname));
+ coucal_write(NewLangList, "projcateg", (intptr_t) strdup(pname));
}
- inthash_write(NewLangList, "loadprojcateg", (intptr_t) NULL);
+ coucal_write(NewLangList, "loadprojcateg", (intptr_t) NULL);
}
/* intial configuration */
{
- if (!inthash_read(NewLangList, "conf_file_loaded", NULL)) {
- inthash_write(NewLangList, "conf_file_loaded",
+ if (!coucal_read(NewLangList, "conf_file_loaded", NULL)) {
+ coucal_write(NewLangList, "conf_file_loaded",
(intptr_t) strdup("true"));
doLoad = 2;
}
@@ -573,8 +573,8 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
if (!commandRunning) {
intptr_t adrpath = 0, adrprojname = 0;
- if (inthash_readptr(NewLangList, "path", &adrpath)
- && inthash_readptr(NewLangList, "projname", &adrprojname)) {
+ if (coucal_readptr(NewLangList, "path", &adrpath)
+ && coucal_readptr(NewLangList, "projname", &adrprojname)) {
StringClear(fspath);
StringCat(fspath, (char *) adrpath);
StringCat(fspath, "/");
@@ -614,7 +614,7 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
if (pos[0] == '0' && pos[1] == '\0')
*pos = '\0'; /* 0 => empty */
unescapeini(pos, &escline);
- inthash_write(NewLangList, line,
+ coucal_write(NewLangList, line,
(intptr_t) StringAcquire(&escline));
}
}
@@ -630,7 +630,7 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
intptr_t adr = 0;
int p = 0;
- if (inthash_readptr(NewLangList, "command", &adr)) {
+ if (coucal_readptr(NewLangList, "command", &adr)) {
if (strcmp((char *) adr, "cancel") == 0) {
if (commandRunning) {
if (!commandEndRequested) {
@@ -674,15 +674,15 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
if (!commandRunning) {
intptr_t adrcd = 0;
- if (inthash_readptr(NewLangList, "command_do", &adrcd)) {
+ if (coucal_readptr(NewLangList, "command_do", &adrcd)) {
intptr_t adrw = 0;
- if (inthash_readptr(NewLangList, "winprofile", &adrw)) {
+ if (coucal_readptr(NewLangList, "winprofile", &adrw)) {
/* User general profile */
intptr_t adruserprofile = 0;
- if (inthash_readptr
+ if (coucal_readptr
(NewLangList, "userprofile", &adruserprofile)
&& adruserprofile != 0) {
int count = (int) strlen((char *) adruserprofile);
@@ -774,7 +774,7 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
} else if (strcmp((char *) adr, "quit") == 0) {
willexit = 1;
}
- inthash_write(NewLangList, "command", (intptr_t) NULL);
+ coucal_write(NewLangList, "command", (intptr_t) NULL);
}
}
@@ -827,7 +827,7 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
} else {
intptr_t adr = 0;
- if (inthash_readptr(NewLangList, "projpath", &adr)) {
+ if (coucal_readptr(NewLangList, "projpath", &adr)) {
sprintf(fsfile, "%s%s", (char *) adr, file + 9);
}
}
@@ -848,7 +848,7 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
"Server: httrack small server\r\n" "Content-type: text/plain\r\n";
/* register current page */
- inthash_write(NewLangList, "thisfile", (intptr_t) strdup(file));
+ coucal_write(NewLangList, "thisfile", (intptr_t) strdup(file));
/* Force GET for the last request */
if (meth == 2 && willexit) {
@@ -863,7 +863,7 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
intptr_t adr = 0;
const char *newfile = file;
- if (inthash_readptr(NewLangList, "redirect", &adr) && adr != 0) {
+ if (coucal_readptr(NewLangList, "redirect", &adr) && adr != 0) {
const char *newadr = (char *) adr;
if (*newadr) {
@@ -879,7 +879,7 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
StringMemcat(headers, tmp, strlen(tmp));
}
}
- inthash_write(NewLangList, "redirect", (intptr_t) NULL);
+ coucal_write(NewLangList, "redirect", (intptr_t) NULL);
} else if (is_html(file)) {
int outputmode = 0;
@@ -983,14 +983,14 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
} else if (strcmp(name, "if-not-empty") == 0) {
intptr_t adr = 0;
- if (!inthash_readptr(NewLangList, pos2, &adr)
+ if (!coucal_readptr(NewLangList, pos2, &adr)
|| *((char *) adr) == 0) {
outputmode = -1;
}
} else if (strcmp(name, "if-empty") == 0) {
intptr_t adr = 0;
- if (inthash_readptr(NewLangList, pos2, &adr)
+ if (coucal_readptr(NewLangList, pos2, &adr)
&& *((char *) adr) != 0) {
outputmode = -1;
}
@@ -999,7 +999,7 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
} else if (strcmp(name, "loadhash") == 0) {
intptr_t adr = 0;
- if (inthash_readptr(NewLangList, "path", &adr)) {
+ if (coucal_readptr(NewLangList, "path", &adr)) {
char *rpath = (char *) adr;
//find_handle h;
@@ -1012,9 +1012,9 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
const char *profiles = hts_getcategories(rpath, 0);
const char *categ = hts_getcategories(rpath, 1);
- inthash_write(NewLangList, "winprofile",
+ coucal_write(NewLangList, "winprofile",
(intptr_t) profiles);
- inthash_write(NewLangList, "wincateg",
+ coucal_write(NewLangList, "wincateg",
(intptr_t) categ);
}
}
@@ -1026,10 +1026,10 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
intptr_t adr = 0;
*pos3++ = '\0';
- if (inthash_readptr(NewLangList, pos2, &adr)) {
- inthash_write(NewLangList, pos3,
+ if (coucal_readptr(NewLangList, pos2, &adr)) {
+ coucal_write(NewLangList, pos3,
(intptr_t) strdup((char *) adr));
- inthash_write(NewLangList, pos2, (intptr_t) NULL);
+ coucal_write(NewLangList, pos2, (intptr_t) NULL);
}
}
}
@@ -1039,10 +1039,10 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
if (pos3) {
*pos3++ = '\0';
- inthash_write(NewLangList, pos2,
+ coucal_write(NewLangList, pos2,
(intptr_t) strdup(pos3));
} else {
- inthash_write(NewLangList, pos2, (intptr_t) NULL);
+ coucal_write(NewLangList, pos2, (intptr_t) NULL);
}
}
}
@@ -1063,7 +1063,7 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
pos2 = strchr(name, ':');
if (pos2 != NULL) {
*pos2 = '\0';
- if (inthash_readptr(NewLangList, name, &adr) || ztest) {
+ if (coucal_readptr(NewLangList, name, &adr) || ztest) {
const char *newadr = (char *) adr;
if (!newadr)
@@ -1123,7 +1123,7 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
dname[0] = '\0';
strncatbuff(dname, name, n2);
- if (inthash_readptr(NewLangList, dname, &adr)) {
+ if (coucal_readptr(NewLangList, dname, &adr)) {
int n = 0;
if (sscanf((char *) adr, "%d", &n) == 1) {
@@ -1148,7 +1148,7 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
if (langstr == NULL || *langstr == '\0') {
intptr_t adr = 0;
- if (inthash_readptr(NewLangList, name, &adr)) {
+ if (coucal_readptr(NewLangList, name, &adr)) {
char *newadr = (char *) adr;
langstr = newadr;
@@ -1411,12 +1411,12 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
int htslang_init(void) {
if (NewLangList == NULL) {
- NewLangList = inthash_new(0);
- inthash_set_name(NewLangList, "NewLangList");
+ NewLangList = coucal_new(0);
+ coucal_set_name(NewLangList, "NewLangList");
if (NewLangList == NULL) {
abortLog("Error in lang.h: not enough memory");
} else {
- inthash_value_is_malloc(NewLangList, 1);
+ coucal_value_is_malloc(NewLangList, 1);
}
}
return 1;
@@ -1424,26 +1424,26 @@ int htslang_init(void) {
int htslang_uninit(void) {
if (NewLangList != NULL) {
- inthash_delete(&NewLangList);
+ coucal_delete(&NewLangList);
}
return 1;
}
int smallserver_setkey(const char *key, const char *value) {
- return inthash_write(NewLangList, key, (intptr_t) strdup(value));
+ return coucal_write(NewLangList, key, (intptr_t) strdup(value));
}
int smallserver_setkeyint(const char *key, LLint value) {
char tmp[256];
snprintf(tmp, sizeof(tmp), LLintP, value);
- return inthash_write(NewLangList, key, (intptr_t) strdup(tmp));
+ return coucal_write(NewLangList, key, (intptr_t) strdup(tmp));
}
int smallserver_setkeyarr(const char *key, int id, const char *key2, const char *value) {
char tmp[256];
snprintf(tmp, sizeof(tmp), "%s%d%s", key, id, key2);
- return inthash_write(NewLangList, tmp, (intptr_t) strdup(value));
+ return coucal_write(NewLangList, tmp, (intptr_t) strdup(value));
}
static int htslang_load(char *limit_to, const char *path) {
@@ -1456,15 +1456,15 @@ static int htslang_load(char *limit_to, const char *path) {
//
if (!limit_to) {
LANG_DELETE();
- NewLangStr = inthash_new(0);
- NewLangStrKeys = inthash_new(0);
- inthash_set_name(NewLangStr, "NewLangStr");
- inthash_set_name(NewLangStrKeys, "NewLangStrKeys");
+ NewLangStr = coucal_new(0);
+ NewLangStrKeys = coucal_new(0);
+ coucal_set_name(NewLangStr, "NewLangStr");
+ coucal_set_name(NewLangStrKeys, "NewLangStrKeys");
if ((NewLangStr == NULL) || (NewLangStrKeys == NULL)) {
abortLog("Error in lang.h: not enough memory");
} else {
- inthash_value_is_malloc(NewLangStr, 1);
- inthash_value_is_malloc(NewLangStrKeys, 1);
+ coucal_value_is_malloc(NewLangStr, 1);
+ coucal_value_is_malloc(NewLangStrKeys, 1);
}
}
@@ -1502,7 +1502,7 @@ static int htslang_load(char *limit_to, const char *path) {
if (buff) {
strcpybuff(buff, intkey);
- inthash_add(NewLangStrKeys, key, (intptr_t) buff);
+ coucal_add(NewLangStrKeys, key, (intptr_t) buff);
}
}
} // if
@@ -1599,7 +1599,7 @@ static int htslang_load(char *limit_to, const char *path) {
char *const buff = (char *) malloc(len + 1);
if (buff) {
conv_printf(value, buff);
- inthash_add(NewLangStr, intkey, (intptr_t) buff);
+ coucal_add(NewLangStr, intkey, (intptr_t) buff);
}
}
@@ -1690,8 +1690,8 @@ static void conv_printf(const char *from, char *to) {
}
static void LANG_DELETE(void) {
- inthash_delete(&NewLangStr);
- inthash_delete(&NewLangStrKeys);
+ coucal_delete(&NewLangStr);
+ coucal_delete(&NewLangStrKeys);
}
// sélection de la langue
@@ -1761,9 +1761,9 @@ static int QLANG_T(int l) {
}
const char* LANGSEL(const char* name) {
- inthash_value value;
+ coucal_value value;
if (NewLangStr != NULL
- && inthash_read_value(NewLangStr, name, &value) != 0
+ && coucal_read_value(NewLangStr, name, &value) != 0
&& value.ptr != NULL) {
return (char*) value.ptr;
} else {
@@ -1772,9 +1772,9 @@ const char* LANGSEL(const char* name) {
}
const char* LANGINTKEY(const char* name) {
- inthash_value value;
+ coucal_value value;
if (NewLangStrKeys != NULL
- && inthash_read_value(NewLangStrKeys, name, &value) != 0
+ && coucal_read_value(NewLangStrKeys, name, &value) != 0
&& value.ptr != NULL) {
return (char*) value.ptr;
} else {
diff --git a/src/htsserver.h b/src/htsserver.h
index 0db7e1c..9b3b125 100644
--- a/src/htsserver.h
+++ b/src/htsserver.h
@@ -71,11 +71,11 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path);
"\r\n"\
extern int NewLangStrSz;
-extern inthash NewLangStr;
+extern coucal NewLangStr;
extern int NewLangStrKeysSz;
-extern inthash NewLangStrKeys;
+extern coucal NewLangStrKeys;
extern int NewLangListSz;
-extern inthash NewLangList;
+extern coucal NewLangList;
extern httrackp *global_opt;
diff --git a/src/htstools.c b/src/htstools.c
index eb5a56b..af41812 100644
--- a/src/htstools.c
+++ b/src/htstools.c
@@ -1079,7 +1079,7 @@ HTSEXT_API char *hts_getcategories(char *path, int type) {
String profiles = STRING_EMPTY;
char *rpath = path;
find_handle h;
- inthash hashCateg = NULL;
+ coucal hashCateg = NULL;
if (rpath[0]) {
if (rpath[strlen(rpath) - 1] == '/') {
@@ -1091,8 +1091,8 @@ HTSEXT_API char *hts_getcategories(char *path, int type) {
String iname = STRING_EMPTY;
if (type == 1) {
- hashCateg = inthash_new(0);
- inthash_set_name(hashCateg, "hashCateg");
+ hashCateg = coucal_new(0);
+ coucal_set_name(hashCateg, "hashCateg");
StringCat(categ, "Test category 1");
StringCat(categ, "\r\nTest category 2");
}
@@ -1117,8 +1117,8 @@ HTSEXT_API char *hts_getcategories(char *path, int type) {
if (n > 0) {
if (strfield(line2, "category=")) {
if (*(line2 + 9)) {
- if (!inthash_read(hashCateg, line2 + 9, NULL)) {
- inthash_write(hashCateg, line2 + 9, 0);
+ if (!coucal_read(hashCateg, line2 + 9, NULL)) {
+ coucal_write(hashCateg, line2 + 9, 0);
if (StringLength(categ) > 0) {
StringCat(categ, "\r\n");
}
@@ -1146,7 +1146,7 @@ HTSEXT_API char *hts_getcategories(char *path, int type) {
StringFree(iname);
}
if (hashCateg) {
- inthash_delete(&hashCateg);
+ coucal_delete(&hashCateg);
hashCateg = NULL;
}
if (type == 1)
diff --git a/src/proxy/store.c b/src/proxy/store.c
index 8c89f4a..e8e98e5 100644
--- a/src/proxy/store.c
+++ b/src/proxy/store.c
@@ -168,7 +168,7 @@ static _PT_Index_Functions _IndexFuncts[] = {
#define PT_INDEX_COMMON_STRUCTURE \
time_t timestamp; \
- inthash hash; \
+ coucal hash; \
char startUrl[1024]
struct _PT_Index__New {
@@ -216,7 +216,7 @@ struct _PT_Index {
};
struct _PT_Indexes {
- inthash cil;
+ coucal cil;
struct _PT_Index **index;
int index_size;
};
@@ -228,7 +228,7 @@ struct _PT_CacheItem {
};
struct _PT_Cache {
- inthash index;
+ coucal index;
size_t maxSize;
size_t totalSize;
int count;
@@ -237,8 +237,8 @@ struct _PT_Cache {
PT_Indexes PT_New(void) {
PT_Indexes index = (PT_Indexes) calloc(sizeof(_PT_Indexes), 1);
- index->cil = inthash_new(0);
- inthash_set_name(index->cil, "index->cil");
+ index->cil = coucal_new(0);
+ coucal_set_name(index->cil, "index->cil");
index->index_size = 0;
index->index = NULL;
return index;
@@ -246,7 +246,7 @@ PT_Indexes PT_New(void) {
void PT_Delete(PT_Indexes index) {
if (index != NULL) {
- inthash_delete(&index->cil);
+ coucal_delete(&index->cil);
free(index);
}
}
@@ -322,7 +322,7 @@ static void PT_Index_Delete__New(PT_Index * pindex) {
index->zFile = NULL;
}
if (index->hash != NULL) {
- inthash_delete(&index->hash);
+ coucal_delete(&index->hash);
index->hash = NULL;
}
MutexFree(&index->zFileLock);
@@ -340,7 +340,7 @@ static void PT_Index_Delete__Old(PT_Index * pindex) {
fclose(index->ndx);
}
if (index->hash != NULL) {
- inthash_delete(&index->hash);
+ coucal_delete(&index->hash);
index->hash = NULL;
}
MutexFree(&index->fileLock);
@@ -429,13 +429,13 @@ char **PT_Enumerate(PT_Indexes indexes, const char *url, int subtree) {
String listindexes = STRING_EMPTY;
String subitem = STRING_EMPTY;
unsigned int listCount = 0;
- struct_inthash_enum en = inthash_enum_new(indexes->cil);
- inthash_item *chain;
- inthash hdupes = NULL;
+ struct_coucal_enum en = coucal_enum_new(indexes->cil);
+ coucal_item *chain;
+ coucal hdupes = NULL;
if (!subtree) {
- hdupes = inthash_new(0);
- inthash_set_name(hdupes, "hdupes");
+ hdupes = coucal_new(0);
+ coucal_set_name(hdupes, "hdupes");
}
StringClear(list);
StringClear(listindexes);
@@ -443,7 +443,7 @@ char **PT_Enumerate(PT_Indexes indexes, const char *url, int subtree) {
if (strncmp(url, "http://", 7) == 0)
url += 7;
urlSize = (unsigned int) strlen(url);
- while((chain = inthash_enum_next(&en))) {
+ while((chain = coucal_enum_next(&en))) {
long int index = (long int) chain->value.intg;
if (urlSize == 0 || strncmp(chain->name, url, urlSize) == 0) {
@@ -462,7 +462,7 @@ char **PT_Enumerate(PT_Indexes indexes, const char *url, int subtree) {
StringClear(subitem);
if (len > 0)
StringMemcat(subitem, item, len);
- if (len == 0 || !inthash_exists(hdupes, StringBuff(subitem))) {
+ if (len == 0 || !coucal_exists(hdupes, StringBuff(subitem))) {
char *ptr = NULL;
ptr += StringLength(list);
@@ -473,7 +473,7 @@ char **PT_Enumerate(PT_Indexes indexes, const char *url, int subtree) {
StringMemcat(list, "\0", 1); /* NULL terminated strings */
StringMemcat(listindexes, (char*) &ptr, sizeof(ptr));
listCount++;
- inthash_write(hdupes, StringBuff(subitem), 0);
+ coucal_write(hdupes, StringBuff(subitem), 0);
}
}
}
@@ -484,7 +484,7 @@ char **PT_Enumerate(PT_Indexes indexes, const char *url, int subtree) {
}
}
StringFree(subitem);
- inthash_delete(&hdupes);
+ coucal_delete(&hdupes);
if (listCount > 0) {
unsigned int i;
void *blk;
@@ -553,8 +553,8 @@ PT_Index PT_LoadCache(const char *filename) {
index->type = type;
index->slots.common.timestamp = (time_t) time(NULL);
index->slots.common.startUrl[0] = '\0';
- index->slots.common.hash = inthash_new(0);
- inthash_set_name(index->slots.common.hash, "index->slots.common.hash");
+ index->slots.common.hash = coucal_new(0);
+ coucal_set_name(index->slots.common.hash, "index->slots.common.hash");
if (!_IndexFuncts[type].PT_LoadCache(index, filename)) {
proxytrack_print_log(DEBUG,
"reading httrack cache (format #%d) %s : error",
@@ -569,12 +569,12 @@ PT_Index PT_LoadCache(const char *filename) {
}
/* default starting URL is the first hash entry */
if (index->slots.common.startUrl[0] == '\0') {
- struct_inthash_enum en = inthash_enum_new(index->slots.common.hash);
- inthash_item *chain;
+ struct_coucal_enum en = coucal_enum_new(index->slots.common.hash);
+ coucal_item *chain;
- chain = inthash_enum_next(&en);
+ chain = coucal_enum_next(&en);
if (chain != NULL && strstr(chain->name, "/robots.txt") != NULL) {
- chain = inthash_enum_next(&en);
+ chain = coucal_enum_next(&en);
}
if (chain != NULL) {
if (!link_has_authority(chain->name))
@@ -625,10 +625,10 @@ int PT_EnumCache(PT_Indexes indexes,
int (*callback) (void *, const char *url, PT_Element),
void *arg) {
if (indexes != NULL && indexes->cil != NULL) {
- struct_inthash_enum en = inthash_enum_new(indexes->cil);
- inthash_item *chain;
+ struct_coucal_enum en = coucal_enum_new(indexes->cil);
+ coucal_item *chain;
- while((chain = inthash_enum_next(&en))) {
+ while((chain = coucal_enum_next(&en))) {
const long int index_id = (long int) chain->value.intg;
const char *const url = chain->name;
@@ -677,7 +677,7 @@ static int PT_LookupCache__New_u(PT_Index index_, const char *url) {
if (strncmp(url, "http://", 7) == 0)
url += 7;
- hash_pos_return = inthash_read(index->hash, url, NULL);
+ hash_pos_return = coucal_read(index->hash, url, NULL);
if (hash_pos_return)
return 1;
}
@@ -689,8 +689,8 @@ int PT_IndexMerge(PT_Indexes indexes, PT_Index * pindex) {
if (pindex != NULL && *pindex != NULL && (*pindex)->slots.common.hash != NULL
&& indexes != NULL) {
PT_Index index = *pindex;
- struct_inthash_enum en = inthash_enum_new(index->slots.common.hash);
- inthash_item *chain;
+ struct_coucal_enum en = coucal_enum_new(index->slots.common.hash);
+ coucal_item *chain;
int index_id = indexes->index_size++;
int nMerged = 0;
@@ -699,13 +699,13 @@ int PT_IndexMerge(PT_Indexes indexes, PT_Index * pindex) {
sizeof(struct _PT_Index) * indexes->index_size)) != NULL) {
indexes->index[index_id] = index;
*pindex = NULL;
- while((chain = inthash_enum_next(&en)) != NULL) {
+ while((chain = coucal_enum_next(&en)) != NULL) {
const char *url = chain->name;
if (url != NULL && url[0] != '\0') {
intptr_t previous_index_id = 0;
- if (inthash_read(indexes->cil, url, &previous_index_id)) {
+ if (coucal_read(indexes->cil, url, &previous_index_id)) {
if (previous_index_id >= 0
&& previous_index_id < indexes->index_size) {
if (indexes->index[previous_index_id]->slots.common.timestamp > index->slots.common.timestamp) // existing entry is newer
@@ -715,7 +715,7 @@ int PT_IndexMerge(PT_Indexes indexes, PT_Index * pindex) {
"PT_IndexMerge:Corrupted central index locator");
}
}
- inthash_write(indexes->cil, chain->name, index_id);
+ coucal_write(indexes->cil, chain->name, index_id);
nMerged++;
}
}
@@ -756,7 +756,7 @@ PT_Element PT_ReadIndex(PT_Indexes indexes, const char *url, int flags) {
if (strncmp(url, "http://", 7) == 0)
url += 7;
- if (inthash_read(indexes->cil, url, &index_id)) {
+ if (coucal_read(indexes->cil, url, &index_id)) {
if (index_id >= 0 && index_id <= indexes->index_size) {
PT_Element item = PT_ReadCache(indexes->index[index_id], url, flags);
@@ -779,7 +779,7 @@ int PT_LookupIndex(PT_Indexes indexes, const char *url) {
if (strncmp(url, "http://", 7) == 0)
url += 7;
- if (inthash_read(indexes->cil, url, &index_id)) {
+ if (coucal_read(indexes->cil, url, &index_id)) {
if (index_id >= 0 && index_id <= indexes->index_size) {
return 1;
} else {
@@ -890,7 +890,7 @@ int PT_LoadCache__New(PT_Index index_, const char *filename) {
if (zFile != NULL) {
const char *abpath;
int slashes;
- inthash hashtable = index->hash;
+ coucal hashtable = index->hash;
/* Compute base path for this index - the filename MUST be absolute! */
for(slashes = 2, abpath = filename + (int) strlen(filename) - 1;
@@ -960,9 +960,9 @@ int PT_LoadCache__New(PT_Index index_, const char *filename) {
}
}
if (dataincache)
- inthash_add(hashtable, filenameIndex, pos);
+ coucal_add(hashtable, filenameIndex, pos);
else
- inthash_add(hashtable, filenameIndex, -pos);
+ coucal_add(hashtable, filenameIndex, -pos);
/* First link as starting URL */
if (!firstSeen) {
@@ -987,7 +987,7 @@ int PT_LoadCache__New(PT_Index index_, const char *filename) {
} while(unzGoToNextFile(zFile) == Z_OK);
return 1;
} else {
- inthash_delete(&index->hash);
+ coucal_delete(&index->hash);
index = NULL;
}
} else {
@@ -1020,7 +1020,7 @@ static PT_Element PT_ReadCache__New_u(PT_Index index_, const char *url,
strcpy(r->location, "");
if (strncmp(url, "http://", 7) == 0)
url += 7;
- hash_pos_return = inthash_read(index->hash, url, &hash_pos);
+ hash_pos_return = coucal_read(index->hash, url, &hash_pos);
if (hash_pos_return) {
uLong posInZip;
@@ -1523,7 +1523,7 @@ static int PT_LoadCache__Old(PT_Index index_, const char *filename) {
sscanf(linepos, "%d", &pos);
/* Add entry */
- inthash_add(cache->hash, line, pos);
+ coucal_add(cache->hash, line, pos);
/* First link as starting URL */
if (!firstSeen) {
@@ -1614,7 +1614,7 @@ static PT_Element PT_ReadCache__Old_u(PT_Index index_, const char *url,
strcpy(r->location, "");
if (strncmp(url, "http://", 7) == 0)
url += 7;
- hash_pos_return = inthash_read(cache->hash, url, &hash_pos);
+ hash_pos_return = coucal_read(cache->hash, url, &hash_pos);
if (hash_pos_return) {
int pos = (int) hash_pos; /* simply */
@@ -1848,7 +1848,7 @@ static int PT_LookupCache__Old_u(PT_Index index_, const char *url) {
return 0;
if (strncmp(url, "http://", 7) == 0)
url += 7;
- if (inthash_read(cache->hash, url, NULL))
+ if (coucal_read(cache->hash, url, NULL))
return 1;
}
return 0;
@@ -2002,7 +2002,7 @@ int PT_LoadCache__Arc(PT_Index index_, const char *filename) {
// Opened ?
if (index->file != NULL) {
- inthash hashtable = index->hash;
+ coucal hashtable = index->hash;
if (readArcURLRecord(index) == 0) {
int entries = 0;
@@ -2046,7 +2046,7 @@ int PT_LoadCache__Arc(PT_Index index_, const char *filename) {
}
/*fprintf(stdout, "adding %s [%d]\n", filenameIndex, (int)fpos); */
if (PT_CompatibleScheme(index->filenameIndexBuff)) {
- inthash_add(hashtable, filenameIndex, fpos); /* position of meta-data */
+ coucal_add(hashtable, filenameIndex, fpos); /* position of meta-data */
entries++;
}
} else {
@@ -2123,7 +2123,7 @@ static PT_Element PT_ReadCache__Arc_u(PT_Index index_, const char *url,
strcpy(r->location, "");
if (strncmp(url, "http://", 7) == 0)
url += 7;
- hash_pos_return = inthash_read(index->hash, url, &hash_pos);
+ hash_pos_return = coucal_read(index->hash, url, &hash_pos);
if (hash_pos_return) {
if (fseek(index->file, (long) hash_pos, SEEK_SET) == 0) {
@@ -2266,7 +2266,7 @@ static int PT_LookupCache__Arc_u(PT_Index index_, const char *url) {
return 0;
if (strncmp(url, "http://", 7) == 0)
url += 7;
- if (inthash_read(cache->hash, url, NULL))
+ if (coucal_read(cache->hash, url, NULL))
return 1;
}
return 0;