From: Brendan Hansen Date: Mon, 21 Dec 2020 18:16:27 +0000 (-0600) Subject: added map.empty and string.compare X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=24066c3dd7f0fa7880e3e239f83e692956d8d690;p=onyx.git added map.empty and string.compare --- diff --git a/core/map.onyx b/core/map.onyx index 15b3cbce..7ee37be5 100644 --- a/core/map.onyx +++ b/core/map.onyx @@ -80,6 +80,10 @@ clear :: proc (use map: ^Map($K, $V)) { entries.count = 0; } +empty :: proc (use map: ^Map($K, $V)) -> bool { + return entries.count == 0; +} + hash_function :: proc { proc (key: rawptr) -> u32 { return 0xcbf29ce7 ^ cast(u32) key; }, proc (key: i32) -> u32 { return 0xcbf29ce7 ^ cast(u32) key; }, diff --git a/core/string.onyx b/core/string.onyx index 9acd2163..b3c6804e 100644 --- a/core/string.onyx +++ b/core/string.onyx @@ -93,15 +93,15 @@ contains :: proc (s: str, c: u8) -> bool { return false; } -// compare :: proc (str1: str, str2: str) -> i32 { -// if str1.count != str2.count do return str1.count - str2.count; -// -// i := 0; -// while i < str1.count && str1[i] == str2[i] do i += 1; -// -// if i == str1.count do return 0; -// return ~~(str1[i] - str2[i]); -// } +// TODO: Check this proc for edge cases and other bugs. I'm not confident +// it will work perfectly yet. - brendanfh 2020/12/21 +compare :: proc (str1: str, str2: str) -> i32 { + i := 0; + while i < str1.count && i < str2.count && str1[i] == str2[i] do i += 1; + + if i == str1.count && i == str2.count do return 0; + return ~~(str1[i] - str2[i]); +} equal :: proc (str1: str, str2: str) -> bool { if str1.count != str2.count do return false; diff --git a/docs/bugs b/docs/bugs index a0e9b3de..90890179 100644 --- a/docs/bugs +++ b/docs/bugs @@ -28,6 +28,9 @@ List of known bugs: [ ] `TileData :: [TILE_DATA_WIDTH * TILE_DATA_HEIGHT] bool;` results in a segfault because it is an invalid top level node, but that is not checked before it is tried to be used. + +[ ] `defer` statements are not executed at the end of a loop if the loop is + exited using a `break` statement, or a `continue` statement. [X] `TileData :: #type [TILE_DATA_WIDTH * TILE_DATA_HEIGHT] bool;` produces the following error: