added 'map.update'
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 24 Dec 2020 19:59:02 +0000 (13:59 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 24 Dec 2020 19:59:02 +0000 (13:59 -0600)
core/map.onyx
docs/bugs
docs/todo

index 7ee37be57290e1daf8af957fecbcad0b398a5e71..96a240a0afe3aa0b165e0b5718b27b1a5a5548f4 100644 (file)
@@ -75,6 +75,13 @@ delete :: proc (use map: ^Map($K, $V), key: K) {
     else                       do hashes[last.hash_index] = lr.entry_index;
 }
 
+update :: proc (use map: ^Map($K, $V), key: K, f: proc (^V)) {
+    lr := lookup(map, key);
+    if lr.entry_index < 0 do return;
+
+    f(^entries[lr.entry_index].value);
+}
+
 clear :: proc (use map: ^Map($K, $V)) {
     for i: 0 .. hashes.count do hashes.data[i] = -1;
     entries.count = 0;
index 5f892b60a384e8ac3218a99ad3acce97184dfe15..a308ab8291f8b3f2ef575644cad55824853ecf09 100644 (file)
--- a/docs/bugs
+++ b/docs/bugs
@@ -38,6 +38,21 @@ List of known bugs:
     Since `continue`ing or `break`ing would skip the deferred statement, causing
     an infinite loop.
 
+[ ] The following code causes an infinite loop somewhere.
+       ```     
+       get_neighbor_count :: proc (grid: ^map.Map(Vec2, Cell), pos: Vec2) -> u32 {
+               count := 0;
+
+               for ^dir: Hex_Directions {
+                       pos  := Vec2.{ x = pos.x + dir.x, y = pos.y + dir.y };
+                       cell := map.get(grid, pos, Cell.{});
+                       if cell.alive do count += 1;
+               }
+
+               return count;
+       }
+       ```
+
 [X] `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.
index cce4d307deccaef8923149f164ac3e11e327670f..d9924b44952428b6f9c4418e1bf4501dce27beb2 100644 (file)
--- a/docs/todo
+++ b/docs/todo
@@ -83,7 +83,7 @@ Language Cohesion:
         types that you can control the name and inadvertently give the same name
         to two different structs / enums.
 
-    [ ] Switches should have range based statements, i.e.
+    [X] Switches should have range based statements, i.e.
             switch expr {
                 case 10 .. 14 do ...
             }
@@ -108,6 +108,10 @@ Language Cohesion:
                 return arr[0 .. N];
             }
 
+    [ ] Functions should return the correct value in all branches.
+
+    [ ] Add macros.
+
 API Expansion:
     There are many different places where the standard API for WASI and JS
     backends could be improved. Here are some of the target areas.