Move string functions/utils from HAL to std/string
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
#include <stdbool.h>
|
||||
#include "hal/hal.h"
|
||||
#include "util/util.h"
|
||||
#include "std/string.h"
|
||||
|
||||
#define HSHTB_FNV32_OFF 0x811c9dc5u
|
||||
#define HSHTB_FNV32_PRIME 0x01000193u
|
||||
@ -32,7 +33,7 @@ enum {
|
||||
#define HSHTB_ALLOC(tb, keyfield, k, out) \
|
||||
do { \
|
||||
size_t __len = __HSHTB_ARRAY_LEN(tb); \
|
||||
uint32_t __h = hshtb_fnv32((k), hal_strlen((k))); \
|
||||
uint32_t __h = hshtb_fnv32((k), strlen((k))); \
|
||||
size_t __idx = __h % __len; \
|
||||
size_t __start = __idx; \
|
||||
typeof(&(tb)[0]) __tomb = NULL; \
|
||||
@ -40,13 +41,13 @@ enum {
|
||||
do { \
|
||||
if ((tb)[__idx]._hshtbstate == HSHTB_EMPTY) { \
|
||||
typeof(&(tb)[0]) __slot = __tomb ? __tomb : &(tb)[__idx]; \
|
||||
hal_memset(__slot, 0, sizeof(*__slot)); \
|
||||
memset(__slot, 0, sizeof(*__slot)); \
|
||||
__slot->_hshtbstate = HSHTB_TAKEN; \
|
||||
hal_memcpy(__slot->keyfield, (k), MIN(sizeof(__slot->keyfield) - 1, hal_strlen((k)))); \
|
||||
memcpy(__slot->keyfield, (k), MIN(sizeof(__slot->keyfield) - 1, strlen((k)))); \
|
||||
(out) = __slot; \
|
||||
break; \
|
||||
} \
|
||||
if ((tb)[__idx]._hshtbstate == HSHTB_TAKEN && hal_strcmp((tb)[__idx].keyfield, (k)) == 0) { \
|
||||
if ((tb)[__idx]._hshtbstate == HSHTB_TAKEN && strcmp((tb)[__idx].keyfield, (k)) == 0) { \
|
||||
(out) = &(tb)[__idx]; \
|
||||
break; \
|
||||
} \
|
||||
@ -60,7 +61,7 @@ enum {
|
||||
#define HSHTB_GET(tb, keyfield, k, out) \
|
||||
do { \
|
||||
size_t __len = __HSHTB_ARRAY_LEN(tb); \
|
||||
uint32_t __h = hshtb_fnv32((k), hal_strlen((k))); \
|
||||
uint32_t __h = hshtb_fnv32((k), strlen((k))); \
|
||||
size_t __idx = __h % __len; \
|
||||
size_t __start = __idx; \
|
||||
(out) = NULL; \
|
||||
@ -68,7 +69,7 @@ enum {
|
||||
if ((tb)[__idx]._hshtbstate == HSHTB_EMPTY) { \
|
||||
break; \
|
||||
} \
|
||||
if ((tb)[__idx]._hshtbstate == HSHTB_TAKEN && hal_strcmp((tb)[__idx].keyfield, (k)) == 0) { \
|
||||
if ((tb)[__idx]._hshtbstate == HSHTB_TAKEN && strcmp((tb)[__idx].keyfield, (k)) == 0) { \
|
||||
(out) = &(tb)[__idx]; \
|
||||
break; \
|
||||
} \
|
||||
|
||||
Reference in New Issue
Block a user