From 112e87f5c78a1f84dd2ccf464318ec59a8bf768f Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Thu, 24 Dec 2020 13:59:02 -0600 Subject: [PATCH] added 'map.update' --- core/map.onyx | 7 +++++++ docs/bugs | 15 +++++++++++++++ docs/todo | 6 +++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/core/map.onyx b/core/map.onyx index 7ee37be5..96a240a0 100644 --- a/core/map.onyx +++ b/core/map.onyx @@ -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; diff --git a/docs/bugs b/docs/bugs index 5f892b60..a308ab82 100644 --- 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. diff --git a/docs/todo b/docs/todo index cce4d307..d9924b44 100644 --- 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. -- 2.25.1