From 9695ea005d4af93dcd60f74f10fd3c54499a182f Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Thu, 11 Nov 2021 16:31:58 -0800 Subject: chore: split up base library into individual files for smaller binaries --- include/base.h | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'include') diff --git a/include/base.h b/include/base.h index b841040..ca229b3 100644 --- a/include/base.h +++ b/include/base.h @@ -51,7 +51,6 @@ void* ·bufgrow(void*, vlong, vlong); // ----------------------------------------------------------------------------- // memory allocation -// TODO(nnoll): Allow for nil iterfaces? /* allocator interface */ typedef struct mem·Allocator { void *(*alloc)(void *heap, uint n, ulong size); @@ -66,7 +65,7 @@ typedef struct mem·Reallocator { void (*free)(void *iface, void *ptr); } mem·Reallocator; -extern mem·Reallocator sys·Relocator; +extern mem·Reallocator sys·FullMemory; /* simple memory arena */ typedef struct mem·Arena mem·Arena; @@ -94,23 +93,23 @@ error coro·free(Coro *c); typedef byte* string; -/* string helpers */ -string str·makecap(const byte *s, vlong len, vlong cap); -string str·makelen(const byte *s, vlong len); -string str·make(const byte *s); -string str·makef(const byte *fmt, ...); +/* augmented string functions */ +string str·makecap(const char *s, vlong len, vlong cap); +string str·makelen(const char *s, vlong len); +string str·make(const char *s); +string str·makef(const char *fmt, ...); void str·free(string s); int str·len(const string s); int str·cap(const string s); void str·clear(string *s); void str·grow(string *s, vlong delta); void str·fit(string *s); -int str·appendlen(string *s, vlong len, const byte *b); -int str·append(string *s, const byte* b); -int str·appendf(string *s, const byte* fmt, ...); -int str·appendbyte(string *s, const byte b); +int str·appendlen(string *s, vlong len, const char *b); +int str·append(string *s, const char *b); +int str·appendf(string *s, const char *fmt, ...); +int str·appendbyte(string *s, const char b); bool str·equals(const string s, const string t); -int str·find(string s, const byte* substr); +int str·find(string s, const char* substr); void str·lower(string s); void str·upper(string s); int str·read(string s, int size, int n, void *buf); @@ -118,6 +117,9 @@ void str·replace(string s, const byte* from, const byte* to); string* str·split(string s, const byte* tok); string str·join(vlong len, byte** fields, const byte* sep); +/* raw C string functions */ +char *str·copyn(char *dst, char *src, int n); + // ----------------------------------------------------------------------------- // i/o @@ -366,22 +368,22 @@ void vpanicf(byte *fmt, va_list args); // ----------------------------------------------------------------------------- // sorting -void sort·ints(uintptr n, int arr[]); -void sort·int8s(uintptr n, int8 arr[]); -void sort·int16s(uintptr n, int16 arr[]); -void sort·int32s(uintptr n, int32 arr[]); -void sort·int64s(uintptr n, int64 arr[]); +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·uints(uintptr n, uint arr[]); -void sort·uint8s(uintptr n, uint8 arr[]); -void sort·uint16s(uintptr n, uint16 arr[]); -void sort·uint32s(uintptr n, uint32 arr[]); -void sort·uint64s(uintptr n, uint64 arr[]); +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·floats(uintptr n, float arr[]); -void sort·doubles(uintptr n, double arr[]); +void sort·float(uintptr n, float arr[]); +void sort·double(uintptr n, double arr[]); -void sort·strings(uintptr n, byte* arr[]); +void sort·string(uintptr n, byte* arr[]); // ----------------------------------------------------------------------------- // fast random number generation @@ -390,6 +392,7 @@ error rng·init(uint64 seed); double rng·random(void); double rng·exponential(double lambda); bool rng·bernoulli(double f); +double rng·normal(void); uint64 rng·randi(int max); uint64 rng·poisson(double mean); -- cgit v1.2.1