2026-05-25 17:27:59 +01:00
|
|
|
#include <fx/collections/hashtable.h>
|
|
|
|
|
#include <fx/int.h>
|
|
|
|
|
#include <fx/reflection/type.h>
|
|
|
|
|
#include <fx/stream.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
|
fx_hashtable *ht = fx_hashtable_create();
|
|
|
|
|
fx_hashtable_put(ht, &FX_INT(32), &FX_INT(64));
|
|
|
|
|
fx_hashtable_put(ht, &FX_CSTR("hello"), &FX_INT(128));
|
|
|
|
|
|
|
|
|
|
const fx_value *v = fx_hashtable_get(ht, &FX_INT(32));
|
|
|
|
|
if (v) {
|
|
|
|
|
printf("32= ");
|
|
|
|
|
fx_value_to_string(v, fx_stdout, NULL);
|
|
|
|
|
printf("\n");
|
|
|
|
|
} else {
|
|
|
|
|
printf("no value\n");
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-28 20:52:40 +01:00
|
|
|
const fx_iterator *it = fx_hashtable_begin(ht);
|
2026-05-25 17:27:59 +01:00
|
|
|
fx_foreach(val, it)
|
|
|
|
|
{
|
|
|
|
|
fx_hashtable_item *item = NULL;
|
2026-05-28 20:52:40 +01:00
|
|
|
fx_value_get_object(val, &item);
|
2026-05-25 17:27:59 +01:00
|
|
|
printf("item %p\n", item);
|
2026-05-28 20:52:40 +01:00
|
|
|
const fx_value *key, *value;
|
2026-05-25 17:27:59 +01:00
|
|
|
key = fx_hashtable_item_get_key(item);
|
|
|
|
|
value = fx_hashtable_item_get_value(item);
|
|
|
|
|
|
|
|
|
|
fx_iterator *prop_it = fx_type_get_properties(
|
|
|
|
|
fx_type_get_by_id(FX_TYPE_HASHTABLE_ITEM));
|
|
|
|
|
fx_foreach(prop_val, prop_it)
|
|
|
|
|
{
|
|
|
|
|
fx_property *prop;
|
2026-05-28 20:52:40 +01:00
|
|
|
fx_value_get_object(prop_val, &prop);
|
2026-05-25 17:27:59 +01:00
|
|
|
printf("%s = ", fx_property_get_name(prop));
|
|
|
|
|
fx_value value = FX_VALUE_EMPTY;
|
2026-05-28 20:52:40 +01:00
|
|
|
fx_property_get_value(prop, val, &value);
|
2026-05-25 17:27:59 +01:00
|
|
|
fx_value_to_string(&value, fx_stdout, NULL);
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
fx_iterator_unref(prop_it);
|
|
|
|
|
}
|
|
|
|
|
fx_iterator_unref(it);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|