reformat code and job array

This commit is contained in:
Rongsong Shen 2025-11-07 16:14:27 +08:00
parent a665ccd4fe
commit 9ff857db9f
64 changed files with 1497 additions and 2476 deletions

View file

@ -5,20 +5,20 @@
#include "htab.h"
#include "utils.h"
#define HASH_KEY_HASH(t, key) \
#define HASH_KEY_HASH(t, key) \
(((t)->fn.hash != NULL) ? ((t)->fn.hash)(key) : (unsigned long)key)
#define HASH_KEY_CMP(t, k1, k2) \
#define HASH_KEY_CMP(t, k1, k2) \
(((t)->fn.cmp != NULL) ? ((t)->fn.cmp)((k1), (k2)) : ((k1) != (k2)))
#define HASH_KEY_COPY(t, key) \
#define HASH_KEY_COPY(t, key) \
(((t)->fn.copy != NULL) ? ((t)->fn.copy)(key) : (key))
#define HASH_KEY_FREE(t, key) \
do { \
if (((t)->fn.free != NULL) && ((key) != NULL)) { \
(t)->fn.free(key); \
} \
#define HASH_KEY_FREE(t, key) \
do { \
if (((t)->fn.free != NULL) && ((key) != NULL)) { \
(t)->fn.free(key); \
} \
} while (0)
static unsigned int hash_code(const char* key)
@ -38,16 +38,12 @@ static unsigned int string_hash(void* data)
return hash_code((const char*)data);
}
static int string_cmp(void* d1,
void* d2)
static int string_cmp(void* d1, void* d2)
{
return (int)strcmp((char*)d1, (char*)d2);
}
static void* string_dup(void* data)
{
return (void*)strdup((char*)data);
}
static void* string_dup(void* data) { return (void*)strdup((char*)data); }
static void string_free(void* data)
{
@ -56,23 +52,15 @@ static void string_free(void* data)
}
}
hash_key_fn_t string_hash_key = {
.hash = (hash_key_hash_fn_t)string_hash,
.cmp = (hash_key_cmp_fn_t)string_cmp,
.copy = (hash_key_copy_fn_t)string_dup,
.free = (hash_key_free_fn_t)string_free
};
hash_key_fn_t string_hash_key = { .hash = (hash_key_hash_fn_t)string_hash,
.cmp = (hash_key_cmp_fn_t)string_cmp,
.copy = (hash_key_copy_fn_t)string_dup,
.free = (hash_key_free_fn_t)string_free };
hash_key_fn_t int_hash_key = {
.hash = NULL,
.cmp = NULL,
.copy = NULL,
.free = NULL
};
hash_key_fn_t int_hash_key
= { .hash = NULL, .cmp = NULL, .copy = NULL, .free = NULL };
int ht_init(htab_t* t,
int nslots,
hash_key_fn_t fn)
int ht_init(htab_t* t, int nslots, hash_key_fn_t fn)
{
if ((t == NULL) || (nslots <= 1)) {
return -EINVAL;
@ -112,8 +100,7 @@ void ht_fini(htab_t* t)
return;
}
hent_t* ht_get(htab_t* t,
void* key)
hent_t* ht_get(htab_t* t, void* key)
{
unsigned int hc;
hent_t* e;
@ -140,8 +127,7 @@ hent_t* ht_get(htab_t* t,
return e;
}
hent_t* ht_add(htab_t* t,
void* key)
hent_t* ht_add(htab_t* t, void* key)
{
unsigned int hc;
hent_t* e;
@ -177,8 +163,7 @@ hent_t* ht_add(htab_t* t,
return e;
}
int ht_del(htab_t* t,
void* key)
int ht_del(htab_t* t, void* key)
{
unsigned int hc;
hent_t** e;