From 6785aa5e51a370c95a5fa2c0f989a5d9120e2852 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Thu, 16 Feb 2023 08:31:04 -0600 Subject: [PATCH] bugfixes and spelling fixes --- core/container/map.onyx | 8 ++++---- core/container/set.onyx | 8 ++++---- core/onyx/cbindgen.onyx | 9 +++------ core/random/random.onyx | 8 +++++++- core/runtime/info/foreign_blocks.onyx | 4 ++-- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/core/container/map.onyx b/core/container/map.onyx index e1a20f8a..2e84faf2 100644 --- a/core/container/map.onyx +++ b/core/container/map.onyx @@ -330,7 +330,7 @@ as_iter :: (m: ^Map) => return lr; } - full :: (use map: ^Map) => entries.count >= (hashes.count * 3) / 4; + full :: (use map: ^Map) => entries.count >= (hashes.count >> 2) * 3; grow :: (use map: ^Map) { new_size := math.max(hashes.count << 1, 8); @@ -348,9 +348,9 @@ as_iter :: (m: ^Map) => for ^entry: entries { defer index += 1; - lr := lookup(map, entry.key); - entries[index].next = hashes[lr.hash_index]; - hashes[lr.hash_index] = index; + hash_index := entry.hash % hashes.count; + entries[index].next = hashes[hash_index]; + hashes[hash_index] = index; } } } diff --git a/core/container/set.onyx b/core/container/set.onyx index 6d831c2a..37939acc 100644 --- a/core/container/set.onyx +++ b/core/container/set.onyx @@ -173,7 +173,7 @@ as_iter :: (s: ^Set) => return lr; } - full :: (use set: ^Set) => entries.count >= ~~(0.75f * ~~hashes.count); + full :: (use set: ^Set) => entries.count >= (hashes.count >> 2) * 3; grow :: (use set: ^Set) { new_size := math.max(hashes.count << 1, 8); @@ -191,9 +191,9 @@ as_iter :: (s: ^Set) => for ^entry: entries { defer index += 1; - lr := lookup(set, entry.value); - entries[index].next = hashes[lr.hash_index]; - hashes[lr.hash_index] = index; + hash_index := entry.hash % hashes.count; + entries[index].next = hashes[hash_index]; + hashes[hash_index] = index; } } } diff --git a/core/onyx/cbindgen.onyx b/core/onyx/cbindgen.onyx index 2162896f..71ba0eae 100644 --- a/core/onyx/cbindgen.onyx +++ b/core/onyx/cbindgen.onyx @@ -197,14 +197,11 @@ compile_c_file :: ( assert(method_info.kind == .Function, "Expected function type."); io.write_format(writer, "ONYX_DEF({}, (", ff.name); - i := 0; + for method_info.parameter_types { - io.write(writer, type_encoding(it)); + if !#first do io.write(writer, ", "); - if i != method_info.parameter_types.count - 1 { - io.write(writer, ", "); - } - i += 1; + io.write(writer, type_encoding(it)); } io.write(writer, "), ("); diff --git a/core/random/random.onyx b/core/random/random.onyx index 20c7ccdd..9553cb90 100644 --- a/core/random/random.onyx +++ b/core/random/random.onyx @@ -11,7 +11,7 @@ Random :: struct { // Creates a new random number generator. // An initial seed can be passed in, otherwise the // current UNIX time is used. - make :: (seed: i64 = core.os.time()) -> Random { + make :: (seed: i64 = (#unquote __initial_value)) -> Random { return .{ seed }; } @@ -106,5 +106,11 @@ string :: (bytes_long: u32, alpha_numeric := false, allocator := context.allocat #package { RANDOM_MULTIPLIER :: 25214903917 RANDOM_INCREMENT :: cast(i64) 11 + + #if #defined(core.os.time) { + __initial_value :: #(core.os.time()) + } else { + __initial_value :: #(8675309) + } } diff --git a/core/runtime/info/foreign_blocks.onyx b/core/runtime/info/foreign_blocks.onyx index e1f8f979..d33de093 100644 --- a/core/runtime/info/foreign_blocks.onyx +++ b/core/runtime/info/foreign_blocks.onyx @@ -4,7 +4,7 @@ package runtime.info // // Foreign Blocks // Because foreign blocks can generate a lot of data, and their data is only -// really helpful in a handful of cases, you need to pass "--generate-foreign-bindings" +// really helpful in a handful of cases, you need to pass "--generate-foreign-info" // to have these arrays filled out. // @@ -26,4 +26,4 @@ get_foreign_block :: (f: foreign_block) -> ^Foreign_Block { if ~~f < cast(i32) 0 || ~~f >= cast(i32) foreign_blocks.count do return null; return foreign_blocks[cast(i32) f]; -} \ No newline at end of file +} -- 2.25.1