1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #include "test_oa_hash_map.h"
- #include "core/os/os.h"
- #include "core/oa_hash_map.h"
- namespace TestOAHashMap {
- MainLoop *test() {
- OS::get_singleton()->print("\n\n\nHello from test\n");
-
- {
- OAHashMap<int, int> map;
- map.set(42, 1337);
- map.set(1337, 21);
- map.set(42, 11880);
- int value;
- map.lookup(42, &value);
- OS::get_singleton()->print("capacity %d\n", map.get_capacity());
- OS::get_singleton()->print("elements %d\n", map.get_num_elements());
- OS::get_singleton()->print("map[42] = %d\n", value);
- }
-
- {
- OAHashMap<int, int> map;
- for (int i = 0; i < 500; i++) {
- map.set(i, i * 2);
- }
- for (int i = 0; i < 500; i += 2) {
- map.remove(i);
- }
- uint32_t num_elems = 0;
- for (int i = 0; i < 500; i++) {
- int tmp;
- if (map.lookup(i, &tmp))
- num_elems++;
- }
- OS::get_singleton()->print("elements %d == %d.\n", map.get_num_elements(), num_elems);
- }
-
- {
- OAHashMap<String, int> map;
- map.set("Hello", 1);
- map.set("World", 2);
- map.set("Godot rocks", 42);
- for (OAHashMap<String, int>::Iterator it = map.iter(); it.valid; it = map.next_iter(it)) {
- OS::get_singleton()->print("map[\"%s\"] = %d\n", it.key->utf8().get_data(), *it.data);
- }
- }
- return NULL;
- }
- }
|