aboutsummaryrefslogtreecommitdiff
path: root/include/base
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-12-10 09:16:08 -0800
committerNicholas Noll <nbnoll@eml.cc>2021-12-10 09:16:08 -0800
commit25537c3d3b9b68af91573dec39d1f46c3d97f735 (patch)
tree3f2ea6207a28fe9610d767dd78fb24d17f858ce0 /include/base
parentf4aef385bdd41b02ef58b5366fa9318ecdc6e37e (diff)
Checkin: small sprawling updates
Small touches to multiple locations in base. Nothing major
Diffstat (limited to 'include/base')
-rw-r--r--include/base/macro/map.h78
-rw-r--r--include/base/math.h1
-rw-r--r--include/base/memory.h5
-rw-r--r--include/base/sort.h26
-rw-r--r--include/base/string.h4
-rw-r--r--include/base/utf.h3
6 files changed, 60 insertions, 57 deletions
diff --git a/include/base/macro/map.h b/include/base/macro/map.h
index 1f07eab..cbcb47d 100644
--- a/include/base/macro/map.h
+++ b/include/base/macro/map.h
@@ -22,8 +22,8 @@ static const double HASHFILL = 0.77;
(flag[i >> 4] &= ~(3ul << ((i & 0xfU) << 1)))
#define map·setdelete(flag, i) (flag[i >> 4] |= 1ul << ((i & 0xfU) << 1))
-#define map·flagsize(m) ((m) < 16 ? 1 : (m) >> 4)
-#define map·fill(m, x) (!map·iseither((m)->flag, (x)))
+#define map·flagsize(m) ((m) < 16 ? 1 : (m) >> 4)
+#define map·filled(m, x) (!map·iseither((m)->flag, (x)))
/* map types */
#define MAP_STRUCT_BODY(key_t, val_t) \
@@ -48,7 +48,7 @@ static const double HASHFILL = 0.77;
(map)->len = (map)->occ = 0; \
}
-#define MAP_GET(i, map, key, hashfunc, equalfunc) \
+#define MAP_GET(map, i, keyv, hashfunc, equalfunc) \
int32 k, last, mask, step; \
if((map)->cap){ \
k = 0; \
@@ -57,11 +57,11 @@ static const double HASHFILL = 0.77;
mask = 0; \
step = 0; \
mask = (map)->cap - 1; \
- k = hashfunc((key)); \
+ k = hashfunc((keyv)); \
i = k & mask; \
last = i; \
while(!map·isempty((map)->flag, i) && \
- (map·isdelete((map)->flag, i) || !equalfunc((map)->key[i], (key)))){ \
+ (map·isdelete((map)->flag, i) || !equalfunc((map)->key[i], (keyv)))){\
i = (i + (++step)) & mask; \
if(i == last){ \
i = (map)->cap; \
@@ -85,7 +85,7 @@ static const double HASHFILL = 0.77;
else{ \
new_flags = (mem).alloc((heap), map·flagsize(newcap), sizeof(int32)); \
if(!new_flags) return -1; \
- mem·set(new_flags, map·flagsize(newcap) * sizeof(int32), 0xAA); \
+ mem·set(new_flags, map·flagsize(newcap)*sizeof(int32), 0xAA); \
if((map)->cap < newcap){ /* expand */ \
key_t *new_keys = (mem).alloc((heap), newcap, sizeof(key_t)); \
if(!new_keys){ \
@@ -154,39 +154,39 @@ static const double HASHFILL = 0.77;
(map)->val = new_vals; \
} \
(mem).free((heap), (map)->flag); /* free the working space */ \
- (map)->flag = new_flags; \
+ (map)->flag = new_flags; \
(map)->cap = newcap; \
- (map)->occ = (map)->len; \
+ (map)->occ = (map)->len; \
(map)->fill = (int32)((map)->cap * HASHFILL + 0.5); \
} \
return 0;
-#define MAP_PUT(map, key, hashfunc, equalfunc, resizefunc, err) \
+#define MAP_PUT(map, newkey, hashfunc, equalfunc, resizefunc, err) \
int32 x = 0; \
- if(map->occ >= map->fill){ \
- if(map->cap > (map->len << 1)){ \
- if(resizefunc(map, map->cap - 1) < 0){ \
+ if((map)->occ >= (map)->fill){ \
+ if((map)->cap > (map)->len << 1){ \
+ if(resizefunc((map), (map)->cap - 1) < 0){ \
*err = -1; \
- return map->cap; \
+ return (map)->cap; \
} \
- }else if(resizefunc(map, map->cap + 1) < 0){ \
+ }else if(resizefunc((map), (map)->cap + 1) < 0){ \
*err = -1; \
- return map->cap; \
+ return (map)->cap; \
} \
} \
\
{ \
- int32 k, i, site, last, mask = map->cap - 1, step = 0; \
- x = site = map->cap; \
- k = hashfunc((key)); \
+ int32 k, i, site, last, mask = (map)->cap - 1, step = 0; \
+ x = site = (map)->cap; \
+ k = hashfunc((newkey)); \
i = k & mask; \
- if(map·isempty(map->flag, i)) \
+ if(map·isempty((map)->flag, i)) \
x = i; /* for speed up */ \
else{ \
last = i; \
- while(!map·isempty(map->flag, i) && \
- (map·isdelete(map->flag, i) || !equalfunc(map->key[i], (key)))){ \
- if(map·isdelete(map->flag, i)) \
+ while(!map·isempty((map)->flag, i) && \
+ (map·isdelete((map)->flag, i) || !equalfunc((map)->key[i], (newkey)))){ \
+ if(map·isdelete((map)->flag, i)) \
site = i; \
i = (i + (++step)) & mask; \
if(i == last){ \
@@ -194,32 +194,32 @@ static const double HASHFILL = 0.77;
break; \
} \
} \
- if(x == map->cap){ \
- if(map·isempty(map->flag, i) && site != map->cap) \
+ if(x == (map)->cap){ \
+ if(map·isempty((map)->flag, i) && site != (map)->cap) \
x = site; \
else \
x = i; \
} \
} \
} \
- if(map·isempty(map->flag, x)){ /* not present at all */ \
- map->key[x] = (key); \
- map·setnotboth(map->flag, x); \
- ++map->len; \
- ++map->occ; \
+ if(map·isempty((map)->flag, x)){ /* not present at all */ \
+ (map)->key[x] = (newkey); \
+ map·setnotboth((map)->flag, x); \
+ ++(map)->len; \
+ ++(map)->occ; \
*err = 1; \
- }else if(map·isdelete(map->flag, x)){ /* deleted */ \
- map->key[x] = (key); \
- map·setnotboth(map->flag, x); \
- ++map->len; \
+ }else if(map·isdelete((map)->flag, x)){ /* deleted */ \
+ (map)->key[x] = (newkey); \
+ map·setnotboth((map)->flag, x); \
+ ++(map)->len; \
}else \
*err = 0; \
return x;
#define MAP_DEL(map, x) \
- if(x != map->cap && !map·iseither(map->flag, x)){ \
- map·setdelete(map->flag, x); \
- --map->len; \
+ if(x != (map)->cap && !map·iseither((map)->flag, x)){ \
+ map·setdelete((map)->flag, x); \
+ --(map)->len; \
}
/* set macro */
@@ -244,7 +244,7 @@ static const double HASHFILL = 0.77;
(set)->len = (set)->occ = 0; \
}
-#define SET_GET(i, set, key, hashfunc, equalfunc ) \
+#define SET_GET(set, i, keyv, hashfunc, equalfunc ) \
int32 k, last, mask, step; \
if((set)->cap){ \
k = 0; \
@@ -253,11 +253,11 @@ static const double HASHFILL = 0.77;
mask = 0; \
step = 0; \
mask = (set)->cap - 1; \
- k = hashfunc((key)); \
+ k = hashfunc((keyv)); \
i = k & mask; \
last = i; \
while(!map·isempty((set)->flag, i) && \
- (map·isdelete((set)->flag, i) || !equalfunc((set)->key[i], (key)))){ \
+ (map·isdelete((set)->flag, i) || !equalfunc((set)->key[i], (keyv)))){\
i = (i + (++step)) & mask; \
if(i == last){ \
i = (set)->cap; \
diff --git a/include/base/math.h b/include/base/math.h
index 69d344e..65d3058 100644
--- a/include/base/math.h
+++ b/include/base/math.h
@@ -19,6 +19,7 @@ double math·log10(double);
double math·exp(double);
double math·floor(double);
double math·ceil(double);
+double math·round(double);
double math·sin(double);
double math·cos(double);
double math·tan(double);
diff --git a/include/base/memory.h b/include/base/memory.h
index 6bf3cbc..a97615e 100644
--- a/include/base/memory.h
+++ b/include/base/memory.h
@@ -31,6 +31,7 @@ typedef struct mem·BufHead
#define mem·buffree(b) ((b) ? (free(mem·bufhdr(b)), (b) = nil) : 0)
#define mem·buffit(b, n) ((n) <= mem·bufcap(b) ? 0 : ((b) = mem·bufgrow((b), (n), sizeof(*(b)))))
+#define mem·bufreset(b) ((b) ? (mem·bufhdr(b)->len=0) : 0)
#define mem·bufpush(b, ...) (mem·buffit((b), 1 + mem·buflen(b)), (b)[mem·bufhdr(b)->len++] = (__VA_ARGS__))
#define mem·bufaddn(b, n) (mem·buffit(b, mem·buflen(b)+n), mem·bufhdr(b)->len += n, b+mem·bufhdr(b)->len-n)
@@ -50,8 +51,8 @@ typedef struct mem·Pool mem·Pool;
typedef struct mem·Arena mem·Arena;
typedef struct mem·Allocator {
- void *(*alloc)(void *heap, long n, uintptr size);
- void *(*realloc)(void *heap, void *ptr, long n, uintptr size);
+ void *(*alloc)(void *heap, uintptr n, uintptr size);
+ void *(*realloc)(void *heap, void *ptr, uintptr n, uintptr size);
void (*free)(void *heap, void *ptr);
} mem·Allocator;
diff --git a/include/base/sort.h b/include/base/sort.h
index e9a0e87..703642e 100644
--- a/include/base/sort.h
+++ b/include/base/sort.h
@@ -1,18 +1,18 @@
#pragma once
-void sort·int(uintptr n, int arr[]);
-void sort·int8(uintptr n, int8 arr[]);
-void sort·int16(uintptr n, int16 arr[]);
-void sort·int32(uintptr n, int32 arr[]);
-void sort·int64(uintptr n, int64 arr[]);
+void sort·int(int arr[], uintptr n);
+void sort·int8(int8 arr[], uintptr n);
+void sort·int16(int16 arr[], uintptr n);
+void sort·int32(int32 arr[], uintptr n);
+void sort·int64(int64 arr[], uintptr n);
-void sort·uint(uintptr n, uint arr[]);
-void sort·uint8(uintptr n, uint8 arr[]);
-void sort·uint16(uintptr n, uint16 arr[]);
-void sort·uint32(uintptr n, uint32 arr[]);
-void sort·uint64(uintptr n, uint64 arr[]);
+void sort·uint(uint arr[], uintptr n);
+void sort·uint8(uint8 arr[], uintptr n);
+void sort·uint16(uint16 arr[], uintptr n);
+void sort·uint32(uint32 arr[], uintptr n);
+void sort·uint64(uint64 arr[], uintptr n);
-void sort·float(uintptr n, float arr[]);
-void sort·double(uintptr n, double arr[]);
+void sort·float(float arr[], uintptr n);
+void sort·double(double arr[], uintptr n);
-void sort·string(uintptr n, byte* arr[]);
+void sort·string(byte* arr[], uintptr n);
diff --git a/include/base/string.h b/include/base/string.h
index 20bf21b..2efbe0a 100644
--- a/include/base/string.h
+++ b/include/base/string.h
@@ -39,8 +39,8 @@ long str·asint(char *s, char **end, int base);
double str·asfloat(char *s, char **end);
/* augmented string functions */
-string string·makecap(char *s, vlong len, vlong cap);
-string string·makelen(char *s, vlong len);
+string string·nnmake(char *s, vlong len, vlong cap);
+string string·nmake(char *s, vlong len);
string string·make(char *s);
string string·makef(char *fmt, ...);
void string·free(string s);
diff --git a/include/base/utf.h b/include/base/utf.h
index 19f345f..b72168c 100644
--- a/include/base/utf.h
+++ b/include/base/utf.h
@@ -31,7 +31,8 @@ int utf8·isspace(rune r);
int utf8·istitle(rune r);
int utf8·ispunct(rune r);
int utf8·isupper(rune r);
-int utf8·islower(rune r);
+
+int utf8·printable(rune r);
rune utf8·toupper(rune r);
rune utf8·tolower(rune r);