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
|
#include "../gb.hpp"
global gb::Heap_Allocator g_heap = {};
inline gb::Allocator*
default_allocator()
{
return &g_heap;
}
int main(int argc, char** argv)
{
// "Use" variables
argc; argv;
using namespace gb;
{
const u8 bytes[4] = {0x00, 0x20, 0xa7, 0x44};
f32 a = reinterpret_cast<const f32&>(bytes);
printf("%f\n", a);
const f32 f = 1337.0f;
u8* fb = (u8*)(&f);
printf("0x%x%x%x%x\n", fb[0], fb[1], fb[2], fb[3]);
}
{
auto table = hash_table::make<f32>(default_allocator());
hash_table::set(&table, 123, 321.0f);
hash_table::set(&table, 456, 654.0f);
#define PGET(key, d) printf("%7d : %7f \n", key, hash_table::get(table, (key), (f32)(d)))
PGET(123, 0);
PGET(456, 0);
PGET(789, 0);
#undef PGET
}
{
String hello = string::make(default_allocator(), "Hello");
String world = string::make(default_allocator(), ", world!", 8);
defer(string::free(hello));
defer(string::free(world));
string::append(&hello, world);
printf("%s\n", hello);
}
for (u32 i = 0; i < 8; i++)
{
u64 bins[10] = {};
auto gen_rand = random::make_random_device();
auto gen = random::make_mt19937_64(random::next(&gen_rand));
for (usize i = 0; i < 200000; i++)
{
u64 result = random::uniform_u64_distribution(&gen, 0, 9);
bins[result]++;
}
for (usize i = 0; i < 10; i++)
{
printf("%2d : ", i);;
u32 a = (u32)(bins[i] / 1000);
for (u32 i = 0; i < a; i++)
printf("*");
printf("\n");
}
time::sleep(time::seconds(1));
}
while (getchar() != '\n')
;
return 0;
}
|