Add primitives, hash map and dynamic array
This commit is contained in:
commit
2f19f82116
10 changed files with 384 additions and 0 deletions
22
include/htd/data_structure/dynamic_array.h
Normal file
22
include/htd/data_structure/dynamic_array.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef DYNAMIC_ARRAY_H
|
||||
#define DYNAMIC_ARRAY_H
|
||||
|
||||
#include <htd/primitives/primitives.h>
|
||||
|
||||
typedef struct {
|
||||
void *data;
|
||||
|
||||
usize len;
|
||||
usize data_size;
|
||||
usize capacity;
|
||||
} DynamicArray;
|
||||
|
||||
void dynarr_init(DynamicArray* arr, usize size);
|
||||
|
||||
void* dynarr_at(DynamicArray* arr, usize idx);
|
||||
|
||||
void dynarr_push(DynamicArray* arr, void* data);
|
||||
|
||||
void dynarr_free(DynamicArray* arr);
|
||||
|
||||
#endif // DYNAMIC_ARRAY_H
|
||||
28
include/htd/data_structure/hash_map.h
Normal file
28
include/htd/data_structure/hash_map.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef HTD_HASH_MAP_H
|
||||
#define HTD_HASH_MAP_H
|
||||
|
||||
#include <htd/primitives/primitives.h>
|
||||
|
||||
typedef struct {
|
||||
void* key;
|
||||
void* val;
|
||||
} HashMapEntry;
|
||||
|
||||
typedef struct {
|
||||
HashMapEntry* table;
|
||||
|
||||
usize len;
|
||||
usize capacity;
|
||||
usize key_size;
|
||||
usize val_size;
|
||||
} HashMap;
|
||||
|
||||
void hmap_init(HashMap* hmap, usize key_size, usize val_size);
|
||||
|
||||
void hmap_put(HashMap* hmap, const void* key, const void* val);
|
||||
|
||||
void* hmap_get(HashMap* hmap, const void* key);
|
||||
|
||||
void hmap_free(HashMap* hmap);
|
||||
|
||||
#endif // HTD_HASH_MAP_H
|
||||
24
include/htd/primitives/primitives.h
Normal file
24
include/htd/primitives/primitives.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef PRIMITIVES_H
|
||||
#define PRIMITIVES_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int8_t i8;
|
||||
typedef int16_t i16;
|
||||
typedef int32_t i32;
|
||||
typedef int64_t i64;
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
// Floats not guaranteed per IEEE 754, but for use case it's fine
|
||||
typedef float f32;
|
||||
typedef double f64;
|
||||
|
||||
typedef size_t usize;
|
||||
typedef ptrdiff_t isize;
|
||||
|
||||
#endif // PRIMITIVES_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue