From 18e408ead4ecee4d8dae8164dd1411b8a9e78149 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 30 May 2025 19:22:17 +0200 Subject: [PATCH] Fix example. --- resources/examples/map.c3 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/resources/examples/map.c3 b/resources/examples/map.c3 index b8dfa0197..2d4fa852a 100644 --- a/resources/examples/map.c3 +++ b/resources/examples/map.c3 @@ -1,9 +1,11 @@ +module std::container::faults; + +faultdef KEY_NOT_FOUND; + module std::container::map{Key, Type}; import std::core::builtin; import std::io; -faultdef KEY_NOT_FOUND; - struct Entry { Key key; @@ -33,17 +35,17 @@ fn void Map.init(Map *map, uint capacity = 128) fn Type? Map.valueForKey(Map *map, Key key) { - if (!map.map) return KEY_NOT_FOUND?; + if (!map.map) return faults::KEY_NOT_FOUND?; uint hash = key.hash(); usz pos = hash & map.mod; Entry* entry = &map.map[pos]; - if (!entry) return KEY_NOT_FOUND?; + if (!entry) return faults::KEY_NOT_FOUND?; while (entry) { if (entry.hash == hash && entry.key == key) return entry.value; entry = entry.next; } - return KEY_NOT_FOUND?; + return faults::KEY_NOT_FOUND?; } fn Type? Map.set(Map *map, Key key, Type value) @maydiscard @@ -65,7 +67,7 @@ fn Type? Map.set(Map *map, Key key, Type value) @maydiscard entry.value = value; entry.hash = hash; entry.key = key; - return KEY_NOT_FOUND?; + return faults::KEY_NOT_FOUND?; } if (entry.hash == hash && entry.key == key) { @@ -85,7 +87,7 @@ fn Type? Map.set(Map *map, Key key, Type value) @maydiscard new.next = null; new.used = true; entry.next = new; - return KEY_NOT_FOUND?; + return faults::KEY_NOT_FOUND?; } }