Fix example.

This commit is contained in:
Christoffer Lerno
2025-05-30 19:22:17 +02:00
parent 08c63108a1
commit 18e408ead4

View File

@@ -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?;
}
}