Skip to content

Instantly share code, notes, and snippets.

@andrewrk
andrewrk / adapted_hash_maps.zig
Last active July 23, 2021 07:13
how to use hash map contexts to save memory when doing a string table
const std = @import("std");
const mem = std.mem;
const Foo = struct {
string_bytes: std.ArrayListUnmanaged(u8),
/// Key is string_bytes index.
string_table: std.HashMapUnmanaged(u32, void, IndexContext, std.hash_map.default_max_load_percentage),
};
const IndexContext = struct {
@minism
minism / binary.lua
Created September 5, 2012 22:31
lua binary data packing
-- Fast functions for working with binary data
return {
decode_uint8 = function(str, ofs)
ofs = ofs or 0
return string.byte(str, ofs + 1)
end,
decode_uint16 = function(str, ofs)
ofs = ofs or 0
local a, b = string.byte(str, ofs + 1, ofs + 2)