From 078e21a1feb811f9ef7797ce3ee5d2e8ffcccfce Mon Sep 17 00:00:00 2001 From: nasr Date: Fri, 17 Apr 2026 17:49:10 +0200 Subject: feature(main): during my work on other projects I improved the base library a bit. this is a drag and drop of that in the project. the next steps exit out of implementing lineair regression and attempting to calcualte what the value would be of a key in the btree... Signed-off-by: nasr feature(main): during my work on other projects I improved the base library a bit. this is a drag and drop of that in the project. the next steps exit out of implementing lineair regression and attempting to calcualte what the value would be of a key in the btree... Signed-off-by: nasr --- source/base/base_string.h | 79 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 24 deletions(-) (limited to 'source/base/base_string.h') diff --git a/source/base/base_string.h b/source/base/base_string.h index 29ccf1e..eb51e65 100644 --- a/source/base/base_string.h +++ b/source/base/base_string.h @@ -1,9 +1,15 @@ #ifndef BASE_STRING_H #define BASE_STRING_H -#define PushString(arena, count) (string8){ .data = (PushArrayZero(arena, u8, (count))), .size = (count) } -#define StringCast(data, size) (string8){(u8 *)(data), (u64)(size) } -#define StringPCast(data, size) (string8 *){(u8 *)(data), (u64)(size) } +#define PushString8(arena, count) (string8){ .data = (PushArrayZero(arena, u8, (count))), .size = (count) } +#define PushString16(arena, count) (string16){ .data = (PushArrayZero(arena, u16, (count))), .size = (count) } +#define PushString32(arena, count) (string32){ .data = (PushArrayZero(arena, u32, (count))), .size = (count) } + +#define String8(data, size) (string8){(u8 *)(data), (u64)(size) } +#define String16(data, size) (string16){(u16 *)(data), (u64)(size) } +#define String32(data, size) (string32){(u32 *)(data), (u64)(size) } + + #define StringFmt "%.*s" #define ULongFmt "%lu" @@ -16,6 +22,51 @@ struct string8 u64 size; }; +typedef struct string16 string16; +struct string16 +{ + u16 *data; + u64 size; +}; + +typedef struct string32 string32; +struct string32 +{ + u32 *data; + u64 size; +}; + +//- string linked list implementation +typedef struct string8_node string8_node; +struct string8_node +{ + string8 *next; + string8 string; +}; + +typedef struct string8_list string8_list; +struct string8_list +{ + string8 *first; + string8 *last; + u64 count; +}; + +typedef struct string16_list string16_list; +struct string16_list +{ + string16 *next; + string16 string; +}; + +typedef struct string32_list string32_list; +struct string32_list +{ + string32 *first; + string32 *last; + u64 count; +}; + internal b8 string8_cmp(string8 a, string8 b) { @@ -23,31 +74,11 @@ string8_cmp(string8 a, string8 b) return (b8)(memcmp(a.data, b.data, a.size) == 0); } -internal u64 -string8_to_u64(u8 *buf, umm len) -{ - u64 value = 0; - for (umm i = 0; i < len; ++i) - { - u8 c = buf[i]; - if (c < '0' || c > '9') break; - value = value * 10 + (c - '0'); - } - return value; -} - internal void -string8_append_char(string8 *buf, u8 c) +string8_appendc(string8 *buf, u8 c) { buf->data[buf->size] = c; buf->size += 1; } -read_only global_variable -string8 nil_string = -{ - .data = NULL, - .size = 0, -}; - #endif /* BASE_STRING_H */ -- cgit v1.3