Skip to content

blockkwork/compmap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CompMap

Compile time hash map that supports keys and values of different data types

📦 Installing

1. Download compmap

2. Copy the code to a zig file (example hmap.zig)

3. Add import to your code:

const hmap = @import("hmap.zig")

also see usage

💡 Info

Data type Key Value
u8 Works Works
u16 Works Works
u32 Works Works
u64 Works Works
u128 Works Works
[]u8 Works Works
[]const u8 Works Works
Signed int - -

🚀 Usage

var hmap = try hashmap.HashMap(u64, u64).init();
defer hmap.deinit();

// 123 - key
// 900 - value
hmap.put(123, 900);
hmap.put(321, 100);

hmap.del(123);
std.debug.print("{}", .{hmap.get(321).?}); // output: 100

Compmap with []const u8 type

var hmap = try hashmap.HashMap([]const u8, u32).init();
defer hmap.deinit();

hmap.put("compmap", 900);
hmap.put("hello", 777);

// get value
const result = hmap.get("hello");
std.debug.print("{}\n", .{result.?}); // output: 777

try hmap.clear(.{}); // delete all buckets

About

Comptime hashmap in zig

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published