aboutsummaryrefslogtreecommitdiffstats
path: root/cm-demo.c
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-03-22 08:58:54 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-03-22 08:58:54 +0100
commita321f937fbe058aa4852e7a6868d4603fb7bfc64 (patch)
tree7f9d759e2a40e77696687e62340b1401c3589d19 /cm-demo.c
parent56b6470095f111d4b98a94d7e6656bb6831179c3 (diff)
finishing raw
Diffstat (limited to 'cm-demo.c')
-rw-r--r--cm-demo.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/cm-demo.c b/cm-demo.c
index c784906..ed90ca1 100644
--- a/cm-demo.c
+++ b/cm-demo.c
@@ -1,7 +1,8 @@
-#include "cheesemap.h"
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <stdint.h>
+
+#include "cheesemap.h"
void* cm_malloc(uintptr_t size, uint8_t* user) {
(void)user;
@@ -31,8 +32,7 @@ bool cm_compare(const uint8_t* key1, const uint8_t* key2, uint8_t* user) {
int main() {
struct cheesemap map;
- cm_new(&map, sizeof(uint64_t), sizeof(uint64_t),
- NULL, cm_malloc, cm_free,
+ cm_new(&map, sizeof(uint64_t), sizeof(uint64_t), NULL, cm_malloc, cm_free,
NULL, cm_hash, cm_compare);
const uint64_t num_entries = 1000000;
@@ -41,9 +41,9 @@ int main() {
for (uint64_t i = 0; i < num_entries; i++) {
uint64_t key = i;
uint64_t value = i * 2;
- bool success = cm_raw_insert(&map.raw, &map.fns,
- sizeof(uint64_t), (uint8_t*)&key,
- sizeof(uint64_t), (uint8_t*)&value);
+ bool success =
+ cm_raw_insert(&map.raw, &map.fns, sizeof(uint64_t), (uint8_t*)&key,
+ sizeof(uint64_t), (uint8_t*)&value);
if (!success) {
printf("Insert failed at i=%lu\n", i);
cm_drop(&map);
@@ -65,19 +65,20 @@ int main() {
uintptr_t entry_size = sizeof(uint64_t) + sizeof(uint64_t);
uintptr_t buckets = map.raw.bucket_mask + 1;
uintptr_t data_size = entry_size * buckets;
- uintptr_t ctrl_size = buckets + 8; // buckets + mirror
+ uintptr_t ctrl_size = buckets + 8; // buckets + mirror
uintptr_t total_size = data_size + ctrl_size;
printf("\nMemory usage:\n");
- printf(" Entries: %lu x %lu bytes = %lu bytes\n",
- buckets, entry_size, data_size);
+ printf(" Entries: %lu x %lu bytes = %lu bytes\n", buckets, entry_size,
+ data_size);
printf(" Control: %lu bytes\n", ctrl_size);
- printf(" Total: %lu bytes (%.2f MB)\n",
- total_size, total_size / (1024.0 * 1024.0));
+ printf(" Total: %lu bytes (%.2f MB)\n", total_size,
+ total_size / (1024.0 * 1024.0));
printf(" Load factor: %.2f%% (%lu / %lu)\n",
(map.raw.count * 100.0) / buckets, map.raw.count, buckets);
printf(" Overhead: %.2f%% ((total - actual) / actual)\n",
- ((total_size - (num_entries * entry_size)) * 100.0) / (num_entries * entry_size));
+ ((total_size - (num_entries * entry_size)) * 100.0) /
+ (num_entries * entry_size));
cm_drop(&map);
printf("\nDone!\n");