// zig run benchmark.zig -lc -O ReleaseFast

const std = @import("std");

usingnamespace @import("hashmap.zig");

pub fn main() !void {
    const allocator = std.heap.c_allocator;

    var map = try HashMap(
        u64,
        u64,
        comptime std.hash_map.getAutoHashFn(u64),
        comptime std.hash_map.getAutoEqlFn(u64),
    ).initCapacity(allocator, 16);
    defer map.deinit(allocator);

    const count = 1_000_000;

    var i: usize = 0;
    while (i < count) : (i += 1) {
        try map.put(allocator, i, i);
    }

    var k: usize = 0;

    while (k < 10) : (k += 1) {
        {
            var j: usize = i;
            while (j < i + count) : (j += 1) {
                try map.put(allocator, j, j);
            }
        }

        {
            var j: usize = i - count;
            while (j < i) : (j += 1) {
                const value = map.remove(allocator, j);
                if (value == null) unreachable;
            }
        }

        i += count;
    }
}