Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/blockkwork/compmap
Comptime hashmap in zig
https://github.com/blockkwork/compmap
Last synced: about 2 months ago
JSON representation
Comptime hashmap in zig
- Host: GitHub
- URL: https://github.com/blockkwork/compmap
- Owner: blockkwork
- Created: 2024-03-31T18:02:05.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-04-01T21:35:37.000Z (9 months ago)
- Last Synced: 2024-04-28T06:12:34.424Z (8 months ago)
- Language: Zig
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CompMap
Compile time hash map that supports keys and values of different data types## 📦 Installing
### 1. Download [compmap](https://raw.githubusercontent.com/blockkwork/compmap/main/src/hashmap.zig)
### 2. Copy the code to a zig file (example hmap.zig)
### 3. Add import to your code:
```zig
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
```zig
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
```zig
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: 777try hmap.clear(.{}); // delete all buckets
```