summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-10-28 10:00:35 +0200
committerTyge Løvset <[email protected]>2022-10-28 10:00:35 +0200
commitd63c37c043024854cfb4b63495e8f5ca3fc03ecd (patch)
tree14c781006a0575c7f2b7515dc5742daaeb916973
parent0243b64f830f55b924274cbc63f5dd1ed518c26f (diff)
downloadSTC-modified-d63c37c043024854cfb4b63495e8f5ca3fc03ecd.tar.gz
STC-modified-d63c37c043024854cfb4b63495e8f5ca3fc03ecd.zip
Renamed some semi-internal functions which appeared to be macros by their name.
-rw-r--r--docs/cmap_api.md8
-rw-r--r--docs/cstr_api.md2
-rw-r--r--examples/vikings.c2
-rw-r--r--include/stc/alt/cstr.h4
-rw-r--r--include/stc/ccommon.h22
-rw-r--r--include/stc/cstr.h6
-rw-r--r--include/stc/csview.h6
7 files changed, 25 insertions, 25 deletions
diff --git a/docs/cmap_api.md b/docs/cmap_api.md
index bf56fcab..4b6ca4bc 100644
--- a/docs/cmap_api.md
+++ b/docs/cmap_api.md
@@ -90,9 +90,9 @@ cmap_X_raw cmap_X_value_toraw(cmap_X_value* pval);
```
Helpers:
```c
-uint64_t c_default_hash(const X *obj); // macro, calls c_fasthash(obj, sizeof *obj)
-uint64_t c_strhash(const char *str); // string hash funcion, uses strlen()
-uint64_t c_fasthash(const void *data, size_t len); // base hash function
+uint64_t c_default_hash(const X *obj); // macro, calls cfasthash(obj, sizeof *obj)
+uint64_t cstrhash(const char *str); // string hash funcion, uses strlen()
+uint64_t cfasthash(const void *data, size_t len); // base hash function
// equalto template parameter functions:
bool c_default_eq(const i_keyraw* a, const i_keyraw* b); // *a == *b
@@ -381,7 +381,7 @@ static inline RViking Viking_toraw(const Viking* vp) {
#define i_keyraw RViking
#define i_keyfrom Viking_from
#define i_opt c_no_clone // disable map cloning
-#define i_hash(rp) (c_strhash(rp->name) ^ c_strhash(rp->country))
+#define i_hash(rp) (cstrhash(rp->name) ^ cstrhash(rp->country))
#define i_val int
#include <stc/cmap.h>
/*
diff --git a/docs/cstr_api.md b/docs/cstr_api.md
index a3211a52..5c7ba41c 100644
--- a/docs/cstr_api.md
+++ b/docs/cstr_api.md
@@ -136,7 +136,7 @@ int cstr_cmp(const cstr* s1, const cstr* s2);
bool cstr_eq(const cstr* s1, const cstr* s2);
bool cstr_hash(const cstr* self);
-char* c_strnstrn(const char* str, const char* search, size_t slen, size_t nlen);
+char* cstrnstrn(const char* str, const char* search, size_t slen, size_t nlen);
```
## Types
diff --git a/examples/vikings.c b/examples/vikings.c
index 4830afdc..a1099d28 100644
--- a/examples/vikings.c
+++ b/examples/vikings.c
@@ -36,7 +36,7 @@ static inline RViking Viking_toraw(const Viking* vp) {
#define i_rawclass RViking // lookup type
#define i_keyfrom Viking_from
#define i_opt c_no_clone
-#define i_hash(rp) c_strhash(rp->name) ^ c_strhash(rp->country)
+#define i_hash(rp) cstrhash(rp->name) ^ cstrhash(rp->country)
#define i_val int // mapped type
#include <stc/cmap.h>
/*
diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h
index fd1d5bb1..17548b5d 100644
--- a/include/stc/alt/cstr.h
+++ b/include/stc/alt/cstr.h
@@ -176,7 +176,7 @@ STC_INLINE bool cstr_eq(const cstr* x, const cstr* y) {
return xs == ys && !memcmp(x->str, y->str, xs);
}
STC_INLINE uint64_t cstr_hash(const cstr *self) {
- return c_fasthash(self->str, _cstr_p(self)->size);
+ return cfasthash(self->str, _cstr_p(self)->size);
}
STC_INLINE void
@@ -323,7 +323,7 @@ cstr_replace_sv(csview str, csview find, csview repl, unsigned count) {
size_t from = 0; char* res;
if (count == 0) count = ~0;
if (find.size)
- while (count-- && (res = c_strnstrn(str.str + from, find.str, str.size - from, find.size))) {
+ while (count-- && (res = cstrnstrn(str.str + from, find.str, str.size - from, find.size))) {
const size_t pos = res - str.str;
cstr_append_n(&out, str.str + from, pos - from);
cstr_append_n(&out, repl.str, repl.size);
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 9395171f..65d90987 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -98,7 +98,7 @@
#define c_default_less(x, y) (*(x) < *(y))
#define c_default_eq(x, y) (*(x) == *(y))
#define c_memcmp_eq(x, y) (memcmp(x, y, sizeof *(x)) == 0)
-#define c_default_hash(x) c_fasthash(x, sizeof *(x))
+#define c_default_hash(x) cfasthash(x, sizeof *(x))
#define c_default_clone(v) (v)
#define c_default_toraw(vp) (*(vp))
@@ -118,7 +118,7 @@
typedef const char* crawstr;
#define crawstr_cmp(xp, yp) strcmp(*(xp), *(yp))
-#define crawstr_hash(p) c_strhash(*(p))
+#define crawstr_hash(p) cstrhash(*(p))
#define c_strlen_lit(literal) (sizeof "" literal - 1U)
#define c_sv(...) c_MACRO_OVERLOAD(c_sv, __VA_ARGS__)
@@ -130,7 +130,7 @@ typedef const char* crawstr;
#define _c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k)))
-STC_INLINE uint64_t c_fasthash(const void* key, size_t len) {
+STC_INLINE uint64_t cfasthash(const void* key, size_t len) {
const uint8_t *x = (const uint8_t*) key;
uint64_t u8, h = 1; size_t n = len >> 3;
uint32_t u4;
@@ -148,18 +148,18 @@ STC_INLINE uint64_t c_fasthash(const void* key, size_t len) {
return _c_ROTL(h, 26) ^ h;
}
-STC_INLINE uint64_t c_strhash(const char *str)
- { return c_fasthash(str, strlen(str)); }
+STC_INLINE uint64_t cstrhash(const char *str)
+ { return cfasthash(str, strlen(str)); }
-STC_INLINE char* c_strnstrn(const char *s, const char *needle,
- size_t slen, const size_t nlen) {
- if (!nlen) return (char *)s;
+STC_INLINE char* cstrnstrn(const char *str, const char *needle,
+ size_t slen, const size_t nlen) {
+ if (!nlen) return (char *)str;
if (nlen > slen) return NULL;
slen -= nlen;
do {
- if (*s == *needle && !memcmp(s, needle, nlen))
- return (char *)s;
- ++s;
+ if (*str == *needle && !memcmp(str, needle, nlen))
+ return (char *)str;
+ ++str;
} while (slen--);
return NULL;
}
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index 3605bab8..5f6e19a8 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -413,11 +413,11 @@ STC_API uint64_t cstr_hash(const cstr *self);
STC_DEF uint64_t cstr_hash(const cstr *self) {
csview sv = cstr_sv(self);
- return c_fasthash(sv.str, sv.size);
+ return cfasthash(sv.str, sv.size);
}
STC_DEF size_t cstr_find_sv(const cstr* self, csview search) {
- char* res = c_strnstrn(cstr_str(self), search.str, cstr_size(self), search.size);
+ char* res = cstrnstrn(cstr_str(self), search.str, cstr_size(self), search.size);
return res ? res - cstr_str(self) : cstr_npos;
}
@@ -540,7 +540,7 @@ cstr_replace_sv(csview in, csview search, csview repl, unsigned count) {
size_t from = 0; char* res;
if (!count) count = ~0;
if (search.size)
- while (count-- && (res = c_strnstrn(in.str + from, search.str, in.size - from, search.size))) {
+ while (count-- && (res = cstrnstrn(in.str + from, search.str, in.size - from, search.size))) {
const size_t pos = res - in.str;
cstr_append_n(&out, in.str + from, pos - from);
cstr_append_n(&out, repl.str, repl.size);
diff --git a/include/stc/csview.h b/include/stc/csview.h
index 566534cc..99a676a6 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -160,12 +160,12 @@ STC_API uint64_t csview_hash(const csview *self);
#if defined(i_implement) || defined(i_extern)
STC_DEF size_t csview_find(csview sv, csview search) {
- char* res = c_strnstrn(sv.str, search.str, sv.size, search.size);
+ char* res = cstrnstrn(sv.str, search.str, sv.size, search.size);
return res ? res - sv.str : csview_npos;
}
STC_DEF uint64_t csview_hash(const csview *self)
- { return c_fasthash(self->str, self->size); }
+ { return cfasthash(self->str, self->size); }
STC_DEF csview csview_substr_ex(csview sv, intptr_t pos, size_t n) {
if (pos < 0) {
@@ -191,7 +191,7 @@ STC_DEF csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2) {
STC_DEF csview csview_token(csview sv, csview sep, size_t* start) {
csview slice = {sv.str + *start, sv.size - *start};
- const char* res = c_strnstrn(slice.str, sep.str, slice.size, sep.size);
+ const char* res = cstrnstrn(slice.str, sep.str, slice.size, sep.size);
csview tok = {slice.str, res ? res - slice.str : slice.size};
*start += tok.size + sep.size;
return tok;