work on refcount

This commit is contained in:
Folkert 2021-02-13 16:41:13 +01:00
parent ac5eb0f6f6
commit e9f2d9d608
5 changed files with 98 additions and 26 deletions

View file

@ -490,6 +490,24 @@ pub fn dictGet(dict: RocDict, alignment: Alignment, key: Opaque, key_width: usiz
}
}
// Dict.elementsRc
// increment or decrement all dict elements (but not the dict's allocation itself)
pub fn elementsRc(dict: RocDict, alignment: Alignment, key_width: usize, value_width: usize, modify_key: Inc, modify_value: Inc) callconv(.C) void {
const size = dict.dict_entries_len;
const n = dict.dict_slot_len;
var i: usize = 0;
i = 0;
while (i < size) : (i += 1) {
modify_key(dict.getKey(n, i, alignment, key_width, value_width));
}
i = 0;
while (i < size) : (i += 1) {
modify_value(dict.getValue(n, i, alignment, key_width, value_width));
}
}
test "RocDict.init() contains nothing" {
const key_size = @sizeOf(usize);
const value_size = @sizeOf(usize);

View file

@ -13,6 +13,7 @@ comptime {
exportDictFn(dict.dictRemove, "remove");
exportDictFn(dict.dictContains, "contains");
exportDictFn(dict.dictGet, "get");
exportDictFn(dict.elementsRc, "elementsRc");
exportDictFn(hash.wyhash, "hash");
exportDictFn(hash.wyhash_rocstr, "hash_str");