Added: Ascii string type and helpers
This commit is contained in:
parent
e882e68959
commit
ccda74a701
|
@ -0,0 +1,21 @@
|
|||
#ifndef HASH_TABLE_H
|
||||
#define HASH_TABLE_H
|
||||
|
||||
typedef u32 Key;
|
||||
|
||||
typedef struct Table Table;
|
||||
struct Table
|
||||
{
|
||||
Arena *ptr_arena;
|
||||
Arena *str8_arena;
|
||||
|
||||
String8 *str8_ptr;
|
||||
u32 str8_count;
|
||||
};
|
||||
|
||||
internal Table hash_store_initialize(void);
|
||||
|
||||
internal String8 hash_store_string8_from_key(Table *table, Key index);
|
||||
internal Key hash_store_string8_to_key(Table *table, String8 value);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,32 @@
|
|||
internal String8
|
||||
str8_init(u8 *cstring, u64 length)
|
||||
{
|
||||
String8 result = { cstring, length };
|
||||
return result;
|
||||
}
|
||||
|
||||
internal u8
|
||||
string8_match(String8 a, String8 b)
|
||||
{
|
||||
u8 result = 0;
|
||||
|
||||
if (a.length == b.length)
|
||||
{
|
||||
u64 size = MIN(a.length, b.length);
|
||||
|
||||
result = 1;
|
||||
for (u64 i = 0; i < size; i++ )
|
||||
{
|
||||
u8 at = a.content[i];
|
||||
i8 bt = b.content[i];
|
||||
|
||||
if (at != bt)
|
||||
{
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef STRING_H
|
||||
#define STRING_H
|
||||
|
||||
typedef struct String8 String8;
|
||||
struct String8
|
||||
{
|
||||
u8 *content;
|
||||
u64 length;
|
||||
};
|
||||
|
||||
internal String8 str8_init(u8 *cstring, u64 length);
|
||||
#define str8_lit(cstring) \
|
||||
str8_init((u8*)(cstring), sizeof(cstring) - 1)
|
||||
|
||||
internal u8 string8_match(String8 a, String8 b);
|
||||
|
||||
#endif // STRING_H
|
Loading…
Reference in New Issue
Block a user