added map.empty and string.compare
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 21 Dec 2020 18:16:27 +0000 (12:16 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 21 Dec 2020 18:16:27 +0000 (12:16 -0600)
core/map.onyx
core/string.onyx
docs/bugs

index 15b3cbce74982d3bb110aa6919a259fa7c4272d5..7ee37be57290e1daf8af957fecbcad0b398a5e71 100644 (file)
@@ -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; },
index 9acd216383e973a71de4fada49f93b28e5416944..b3c6804efc88d78e4c3fab64eee2f133300eba39 100644 (file)
@@ -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;
index a0e9b3de414541721fd7bc8b1f0bdb56390f0df6..90890179ea7f8f28802688b67b0e947f6461c836 100644 (file)
--- 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: