fx.collections: update iterator semantics

This commit is contained in:
2026-05-28 20:52:40 +01:00
parent 883b0b24b1
commit ff0d40b324
8 changed files with 143 additions and 116 deletions
+6 -5
View File
@@ -32,8 +32,9 @@ struct fx_hashmap_p {
struct fx_hashmap_iterator_p {
size_t i;
fx_hashmap_item item;
fx_value item_value;
fx_hashmap *_h;
const fx_hashmap *_h;
struct fx_hashmap_p *_h_p;
fx_bst_node *_cbn;
fx_queue_entry *_cqe;
@@ -420,7 +421,7 @@ bool fx_hashmap_is_empty(const fx_hashmap *hashmap)
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_HASHMAP, hashmap_is_empty, hashmap);
}
fx_iterator *fx_hashmap_begin(fx_hashmap *hashmap)
const fx_iterator *fx_hashmap_begin(const fx_hashmap *hashmap)
{
fx_hashmap_iterator *it_obj = fx_object_create(
FX_TYPE_HASHMAP_ITERATOR);
@@ -617,12 +618,13 @@ static enum fx_status iterator_erase(fx_iterator *obj)
return FX_SUCCESS;
}
static fx_value iterator_get_value(const fx_iterator *obj)
static const fx_value *iterator_get_value(const fx_iterator *obj)
{
struct fx_hashmap_iterator_p *it = fx_object_get_private(
obj,
FX_TYPE_HASHMAP_ITERATOR);
return FX_POINTER(&it->item);
it->item_value = FX_POINTER(&it->item);
return &it->item_value;
}
/*** CLASS DEFINITION *********************************************************/
@@ -635,7 +637,6 @@ FX_TYPE_CLASS_BEGIN(fx_hashmap)
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
FX_INTERFACE_ENTRY(it_begin) = fx_hashmap_begin;
FX_INTERFACE_ENTRY(it_cbegin) = fx_hashmap_cbegin;
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
FX_TYPE_CLASS_END(fx_hashmap)