-
Notifications
You must be signed in to change notification settings - Fork 0
/
ytypes.h
executable file
·128 lines (111 loc) · 2.83 KB
/
ytypes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ytypes.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ihhrabar <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/10 11:38:27 by ihhrabar #+# #+# */
/* Updated: 2023/03/10 11:38:28 by ihhrabar ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef YTYPES_H
# define YTYPES_H
// Because "unsigned int" is too long
typedef unsigned int t_uint;
typedef long int t_uint_ptr;
typedef unsigned char t_uchar;
typedef unsigned short t_ushort;
// A structure representing the list of pointers to the data.
// s_list does not own the values themselves
typedef struct s_list
{
unsigned int size;
unsigned int capacity;
void **data;
} t_list;
// List iterator
typedef struct s_list_iter
{
void *value;
unsigned int i;
t_list *list;
} t_list_iter;
// Represents a boolean value
typedef enum e_bool
{
FALSE,
TRUE
} t_bool;
// Represents a mutable, null-termintated string
typedef struct s_string
{
char *cstr;
unsigned int size;
} t_string;
// 2D vector of integers
typedef struct s_ivec2
{
int x;
int y;
} t_ivec2;
// 2D vector of doubles
typedef struct s_dvec2
{
double x;
double y;
} t_dvec2;
// 3D vector of integers
typedef struct s_ivec3
{
int x;
int y;
int z;
} t_ivec3;
// 3D vector of doubles
typedef struct s_dvec3
{
double x;
double y;
double z;
} t_dvec3;
// Hash function for hash maps and sets
typedef t_uint (*t_hash_func)(void *);
// Equals function for hash maps and sets
typedef t_bool (*t_equals_func)(void *, void *);
typedef struct s_kv_pair
{
void *key;
void *value;
} t_kv_pair;
// Hash Map item container (is private/not meant to be used outside of yLib)
struct s_map_item_container
{
t_uint hash;
t_kv_pair item;
};
// Hash Map container
// (bucket_array is array of lists of s_map_item_containers)
typedef struct s_map
{
t_hash_func hash_func;
t_equals_func equals_func;
t_list *bucket_array;
t_uint bucket_array_size;
double upper_realloc_ratio;
double lower_realloc_ratio;
t_uint upper_realloc_value;
t_uint lower_realloc_value;
double scaling_ratio;
t_uint size;
} t_map;
// TODO: Map key-value pair iterator
typedef struct s_map_iter
{
void *value;
void *key;
t_uint bucket;
t_list_iter bucket_iter;
t_map *map;
} t_map_iter;
#endif