diff --git a/Makefile b/Makefile index a69919e1..813edb28 100644 --- a/Makefile +++ b/Makefile @@ -65,9 +65,8 @@ distclean: lib: $(LIB_PATH) $(LIB_PATH): $(LIB_OBJS) - @printf "\r\e[2K%s\n" "$(AR_RCS) $@" + @printf "\r\e[2K%s" "$(AR_RCS) $@" @$(AR_RCS) $@ $(LIB_OBJS) -# @echo "" $(OBJ_DIR)/%.o: %.c @$(MKDIR_P) $(@D) @@ -85,7 +84,7 @@ $(OBJ_DIR)/%$(DOTEXE): %.c $(LIB_PATH) @$(CC) -o $@ $(CFLAGS) -s $< $(LDFLAGS) -L$(BUILDDIR) -l$(LIB_NAME) $(TEST_EXE): $(TEST_OBJS) - @printf "\r\e[2K%s" "$(CC) -o $@ $(notdir $(TEST_OBJS))" + @printf "\r\e[2K%s" "$(CC) -o $@" @$(CC) -o $@ $(TEST_OBJS) -s $(LDFLAGS) -L$(BUILDDIR) -l$(LIB_NAME) diff --git a/include/stc/common.h b/include/stc/common.h index 290a6ec9..2b5d391f 100644 --- a/include/stc/common.h +++ b/include/stc/common.h @@ -237,11 +237,19 @@ typedef const char* cstr_raw; // General functions -// substring in substring? -char* c_strnstrn(const char *str, isize slen, const char *needle, isize nlen); - -// hashing -size_t c_basehash_n(const void* key, isize len); +STC_INLINE size_t c_basehash_n(const void* key, isize len) { + size_t block = 0, hash = 0x811c9dc5; + const uint8_t* msg = (const uint8_t*)key; + while (len >= c_sizeof(size_t)) { + memcpy(&block, msg, sizeof(size_t)); + hash = (hash ^ block) * (size_t)0x89bb179901000193; + msg += c_sizeof(size_t); + len -= c_sizeof(size_t); + } + c_memcpy(&block, msg, len); + hash = (hash ^ block) * (size_t)0xb0340f4501000193; + return hash ^ (hash >> 3); +} STC_INLINE size_t c_hash_n(const void* key, isize len) { uint64_t b8; uint32_t b4; @@ -255,12 +263,13 @@ STC_INLINE size_t c_hash_n(const void* key, isize len) { STC_INLINE size_t c_hash_str(const char *str) { return c_basehash_n(str, c_strlen(str)); } +#define c_hash_mix(...) /* non-commutative hash combine! */ \ + _chash_mix(c_make_array(size_t, {__VA_ARGS__}), c_NUMARGS(__VA_ARGS__)) + STC_INLINE size_t _chash_mix(size_t h[], int n) { for (int i = 1; i < n; ++i) h[0] += h[0] ^ h[i]; return h[0]; } -#define c_hash_mix(...) /* non-commutative hash combine! */ \ - _chash_mix(c_make_array(size_t, {__VA_ARGS__}), c_NUMARGS(__VA_ARGS__)) // generic typesafe swap #define c_swap(xp, yp) do { \ @@ -283,12 +292,8 @@ STC_INLINE isize c_next_pow2(isize n) { #endif return n + 1; } -#endif // STC_COMMON_H_INCLUDED - -#if !defined STC_COMMON_C_INCLUDED && defined STC_IMPLEMENT -#define STC_COMMON_C_INCLUDED -char* c_strnstrn(const char *str, isize slen, const char *needle, isize nlen) { +STC_INLINE char* c_strnstrn(const char *str, isize slen, const char *needle, isize nlen) { if (nlen == 0) return (char *)str; if (nlen > slen) return NULL; slen -= nlen; @@ -299,18 +304,4 @@ char* c_strnstrn(const char *str, isize slen, const char *needle, isize nlen) { } while (slen--); return NULL; } - -size_t c_basehash_n(const void* key, isize len) { - size_t block = 0, hash = 0x811c9dc5; - const uint8_t* msg = (const uint8_t*)key; - while (len >= c_sizeof(size_t)) { - memcpy(&block, msg, sizeof(size_t)); - hash = (hash ^ block) * (size_t)0x89bb179901000193; - msg += c_sizeof(size_t); - len -= c_sizeof(size_t); - } - c_memcpy(&block, msg, len); - hash = (hash ^ block) * (size_t)0xb0340f4501000193; - return hash ^ (hash >> 3); -} -#endif // STC_COMMON_C_INCLUDED +#endif // STC_COMMON_H_INCLUDED diff --git a/include/stc/cspan.h b/include/stc/cspan.h index 7a945041..5ad40145 100644 --- a/include/stc/cspan.h +++ b/include/stc/cspan.h @@ -335,7 +335,7 @@ STC_API _istride* _cspan_shape2stride(cspan_layout layout, _istride shape[], int #endif // STC_CSPAN_H_INCLUDED /* --------------------- IMPLEMENTATION --------------------- */ -#if defined i_implement || defined i_static +#if defined i_implement STC_DEF void _cspan_print_assist(_istride pos[], const _istride shape[], const int rank, char result[2][16], const char* brackets) { diff --git a/include/stc/cstr.h b/include/stc/cstr.h index a35c3dcc..f61d0364 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -37,7 +37,7 @@ #endif // STC_CSTR_H_INCLUDED -#if defined i_implement || defined STC_IMPLEMENT || \ +#if defined i_implement || \ defined STC_CSTR_CORE || \ defined STC_CSTR_IO || \ defined STC_CSTR_UTF8 diff --git a/include/stc/deque.h b/include/stc/deque.h index 24516a69..6f8c4e79 100644 --- a/include/stc/deque.h +++ b/include/stc/deque.h @@ -124,7 +124,7 @@ _c_MEMB(_find)(const Self* self, _m_raw raw) { #endif // _i_has_cmp /* -------------------------- IMPLEMENTATION ------------------------- */ -#if defined(i_implement) || defined(i_static) +#if defined i_implement STC_DEF _m_value* _c_MEMB(_push_front)(Self* self, _m_value value) { diff --git a/include/stc/hmap.h b/include/stc/hmap.h index 4f1bb37d..7e59dd12 100644 --- a/include/stc/hmap.h +++ b/include/stc/hmap.h @@ -292,7 +292,7 @@ _c_MEMB(_eq)(const Self* self, const Self* other) { } /* -------------------------- IMPLEMENTATION ------------------------- */ -#if defined(i_implement) || defined(i_static) +#if defined i_implement STC_DEF _m_iter _c_MEMB(_begin)(const Self* self) { _m_iter it = {self->table, self->table, self->meta}; diff --git a/include/stc/list.h b/include/stc/list.h index 5e49cbb9..4074f7c2 100644 --- a/include/stc/list.h +++ b/include/stc/list.h @@ -222,7 +222,7 @@ STC_INLINE bool _c_MEMB(_eq)(const Self* self, const Self* other) { #endif // -------------------------- IMPLEMENTATION ------------------------- -#if defined(i_implement) || defined(i_static) +#if defined i_implement #if !defined i_no_clone STC_DEF Self diff --git a/include/stc/pqueue.h b/include/stc/pqueue.h index 72948d76..e66916fa 100644 --- a/include/stc/pqueue.h +++ b/include/stc/pqueue.h @@ -130,7 +130,7 @@ STC_INLINE void _c_MEMB(_emplace)(Self* self, _m_raw raw) #endif // !i_no_emplace /* -------------------------- IMPLEMENTATION ------------------------- */ -#if defined(i_implement) || defined(i_static) +#if defined i_implement STC_DEF void _c_MEMB(_sift_down_)(Self* self, const isize idx, const isize n) { diff --git a/include/stc/priv/linkage.h b/include/stc/priv/linkage.h index 09f2ce36..c1b8def0 100644 --- a/include/stc/priv/linkage.h +++ b/include/stc/priv/linkage.h @@ -23,12 +23,12 @@ #undef STC_API #undef STC_DEF -#if !defined i_static && !defined STC_STATIC && (defined i_header || defined STC_HEADER || \ - defined i_implement || defined STC_IMPLEMENT) +#if !defined i_static && !defined STC_STATIC && (defined i_header || defined STC_HEADER || \ + defined i_implement || defined STC_IMPLEMENT) #define STC_API extern #define STC_DEF #else - #define i_static + #define i_implement #if defined __GNUC__ || defined __clang__ #define STC_API static __attribute__((unused)) #else diff --git a/include/stc/priv/queue_prv.h b/include/stc/priv/queue_prv.h index 15c98de6..ee84724c 100644 --- a/include/stc/priv/queue_prv.h +++ b/include/stc/priv/queue_prv.h @@ -150,7 +150,7 @@ STC_INLINE void _c_MEMB(_adjust_end_)(Self* self, isize n) { self->end = (self->end + n) & self->capmask; } /* -------------------------- IMPLEMENTATION ------------------------- */ -#if defined i_implement || defined i_static +#if defined i_implement STC_DEF _m_iter _c_MEMB(_advance)(_m_iter it, isize n) { isize len = _c_MEMB(_size)(it._s); diff --git a/include/stc/priv/sort_prv.h b/include/stc/priv/sort_prv.h index 2a237a02..1301eb23 100644 --- a/include/stc/priv/sort_prv.h +++ b/include/stc/priv/sort_prv.h @@ -64,7 +64,7 @@ _c_MEMB(_binary_search)(const Self* self, const _m_raw raw) #endif /* -------------------------- IMPLEMENTATION ------------------------- */ -#if defined i_implement || defined i_static +#if defined i_implement static void _c_MEMB(_insertsort_lowhigh)(Self* self, isize lo, isize hi) { for (isize j = lo, i = lo + 1; i <= hi; j = i, ++i) { diff --git a/include/stc/random.h b/include/stc/random.h index 5b5423c2..ca6c3bdc 100644 --- a/include/stc/random.h +++ b/include/stc/random.h @@ -220,7 +220,7 @@ STC_INLINE int64_t crand32_uniform(crand32_uniform_dist* d) #endif // STC_RANDOM_H_INCLUDED /* -------------------------- IMPLEMENTATION ------------------------- */ -#if defined i_implement || defined i_static +#if defined i_implement #ifndef STC_RANDOM_C_INCLUDED #define STC_RANDOM_C_INCLUDED diff --git a/include/stc/smap.h b/include/stc/smap.h index f66cb04f..6bbe623b 100644 --- a/include/stc/smap.h +++ b/include/stc/smap.h @@ -259,7 +259,7 @@ STC_INLINE Self _c_MEMB(_with_n)(const _m_raw* raw, isize n) { Self cx = {0}; _c_MEMB(_put_n)(&cx, raw, n); return cx; } /* -------------------------- IMPLEMENTATION ------------------------- */ -#if defined(i_implement) || defined(i_static) +#if defined i_implement STC_DEF void _c_MEMB(_next)(_m_iter *it) { diff --git a/include/stc/vec.h b/include/stc/vec.h index 65293218..c046a17f 100644 --- a/include/stc/vec.h +++ b/include/stc/vec.h @@ -261,7 +261,7 @@ STC_INLINE bool _c_MEMB(_eq)(const Self* self, const Self* other) { #endif // _i_has_cmp /* -------------------------- IMPLEMENTATION ------------------------- */ -#if defined i_implement || defined i_static +#if defined i_implement STC_DEF void _c_MEMB(_clear)(Self* self) {