Handle map iterator reset for reuse + fix example#6335
Merged
Kelimion merged 4 commits intoodin-lang:masterfrom Feb 25, 2026
Merged
Handle map iterator reset for reuse + fix example#6335Kelimion merged 4 commits intoodin-lang:masterfrom
Kelimion merged 4 commits intoodin-lang:masterfrom
Conversation
Member
|
I propose a slightly different diff to make the example more easily compileable:
Also, your This does. But please do keep the diff --git a/core/container/handle_map/doc.odin b/core/container/handle_map/doc.odin
index fe4154774..088ba37d7 100644
--- a/core/container/handle_map/doc.odin
+++ b/core/container/handle_map/doc.odin
@@ -24,10 +24,12 @@ Example:
hm.remove(&entities, h1)
h3 := hm.add(&entities, Entity{pos = {6, 7}})
+ assert(hm.is_valid(entities, h3))
it := hm.iterator_make(&entities)
for e, h in hm.iterate(&it) {
e.pos += {1, 2}
+ assert(hm.is_valid(entities, h))
}
}
@@ -46,10 +48,12 @@ Example:
hm.remove(&entities, h1)
h3 := hm.add(&entities, Entity{pos = {6, 7}})
+ assert(hm.is_valid(&entities, h3))
it := hm.iterator_make(&entities)
for e, h in hm.iterate(&it) {
e.pos += {1, 2}
+ assert(hm.is_valid(&entities, h))
}
}
*/
diff --git a/core/container/handle_map/dynamic_handle_map.odin b/core/container/handle_map/dynamic_handle_map.odin
index 4024ac5b6..bdd9b7daf 100644
--- a/core/container/handle_map/dynamic_handle_map.odin
+++ b/core/container/handle_map/dynamic_handle_map.odin
@@ -31,7 +31,7 @@ dynamic_destroy :: proc(m: ^$D/Dynamic_Handle_Map($T, $Handle_Type)) {
}
@(require_results)
-dynamic_add :: proc(m: ^$D/Dynamic_Handle_Map($T, $Handle_Type), item: T, loc := #caller_location) -> (handle: Handle_Type, err: runtime.Allocator_Error) {
+dynamic_add :: proc(m: ^$D/Dynamic_Handle_Map($T, $Handle_Type), item: T, loc := #caller_location) -> (handle: Handle_Type, err: runtime.Allocator_Error) #optional_allocator_error {
if xar.len(m.unused_items) > 0 {
i := xar.pop(&m.unused_items)
ptr := xar.get_ptr_unsafe(&m.items, i) |
This reverts commit 91a27e5.
… handle_map example to use is_valid
Contributor
Author
|
I've made those updates. One minor change to move the assert above the access to e.pos. Thanks! |
Member
|
Squahed and merged. Thanks. :-) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reset the handle_map iterators for easy reuse and make the example more compilable.