ensure_capacity :: (arr: ^[..] $T, capacity: u32) -> bool {
if arr.capacity >= capacity do return true;
+ if arr.data == null do init(arr);
while capacity > arr.capacity do arr.capacity <<= 1;
new_data := raw_resize(arr.allocator, arr.data, sizeof T * arr.capacity);
}
put :: (use map: ^Map($K, $V), key: K, value: V) {
+ if map.hashes.data == null do init(map);
lr := lookup(map, key);
if lr.entry_index >= 0 {
}
lookup :: (use map: ^Map($K, $V), key: K) -> MapLookupResult {
+ if hashes.data == null do init(map);
lr := MapLookupResult.{};
hash_value: u32 = hash.to_u32(key); // You cannot use this type for the key, unless you add an overload.
--- /dev/null
+data: 0x0 count: 0
+data: 0x100 count: 100
+Untyped_Array {
+ data = (null),
+ count = 0,
+ capacity = 0,
+ allocator = Allocator {
+ data = (null),
+ func = func[0]
+ }
+}
+Map([] u8, i32) {
+ allocator = Allocator {
+ data = 0xB750,
+ func = func[38]
+ },
+ hashes = [
+ -1,
+ -1,
+ -1,
+ 1,
+ -1,
+ -1,
+ -1,
+ -1
+ ],
+ entries = [
+ Map.Entry([] u8, i32) {
+ next = -1,
+ key = "Joe",
+ value = 12
+ },
+ Map.Entry([] u8, i32) {
+ next = 0,
+ key = "Jane",
+ value = 34
+ }
+ ],
+ default_value = 0
+}
--- /dev/null
+#load "core/std"
+
+use package core
+
+main :: (args) => {
+ {
+ x: [] i32;
+ printf("data: {} count: {}\n", x.data, x.count);
+
+ y := ([] i32).{ ~~ 0x100, 100 };
+ printf("data: {} count: {}\n", y.data, y.count);
+ }
+
+ {
+ arr: [..] i32;
+ printf("{*p}\n", cast(^array.Untyped_Array) ^arr);
+
+ people: Map(str, i32);
+ people["Joe"] = 12;
+ people["Jane"] = 34;
+ printf("{*p}\n", ^people);
+ }
+}
\ No newline at end of file