|
| 1 | +#ifndef __RECOMPDATA_H__ |
| 2 | +#define __RECOMPDATA_H__ |
| 3 | + |
| 4 | +#include "modding.h" |
| 5 | + |
| 6 | +// This file contains imports for utility data collection types. |
| 7 | +// hashmaps: Maps arbitrary unique numeric keys to elements. |
| 8 | +// Amortized O(1) performance for insertion, lookup, and deletion. |
| 9 | +// hashsets: Tracks a collection of unique numeric keys. |
| 10 | +// Amortized O(1) performance for insertion, lookup, and deletion. |
| 11 | +// slotmaps: Like hashmaps, but the keys are generated instead of provided. |
| 12 | +// Amortized O(1) performance for insertion, lookup, and deletion. More performant than hashmaps. |
| 13 | + |
| 14 | +// Hashmaps and slotmaps types are available that hold either 32-bit elements or data elements of a fixed element size. |
| 15 | + |
| 16 | +typedef unsigned long collection_key_t; |
| 17 | + |
| 18 | +///////////////////////// |
| 19 | +// u32 -> u32 hashmaps // |
| 20 | +///////////////////////// |
| 21 | + |
| 22 | +typedef unsigned long U32ValueHashmapHandle; |
| 23 | + |
| 24 | +// Creates a hashmap that maps u32 keys to u32 values. |
| 25 | +// Returns the handle for that hashmap. |
| 26 | +RECOMP_IMPORT("*", U32ValueHashmapHandle recomputil_create_u32_value_hashmap()); |
| 27 | + |
| 28 | +// Destroys a u32 -> u32 hashmap. |
| 29 | +RECOMP_IMPORT("*", void recomputil_destroy_u32_value_hashmap(U32ValueHashmapHandle handle)); |
| 30 | + |
| 31 | +// Checks if a u32 -> u32 hashmap contains the given key. |
| 32 | +// Returns 1 if the key exists in the map, otherwise returns 0. |
| 33 | +RECOMP_IMPORT("*", int recomputil_u32_value_hashmap_contains(U32ValueHashmapHandle handle, collection_key_t key)); |
| 34 | + |
| 35 | +// Inserts a value into a u32 -> u32 hashmap. The value is always assigned even if the key already exists. |
| 36 | +// Returns 1 if the key was created (i.e. did not exist in the map), otherwise returns 0. |
| 37 | +RECOMP_IMPORT("*", int recomputil_u32_value_hashmap_insert(U32ValueHashmapHandle handle, collection_key_t key, unsigned long value)); |
| 38 | + |
| 39 | +// Attempts to retrieve a value from a u32 -> u32 hashmap. |
| 40 | +// Returns 1 if the key exists in the map and writes the element's value to *out, otherwise returns 0 and does not modify the contents in *out. |
| 41 | +RECOMP_IMPORT("*", int recomputil_u32_value_hashmap_get(U32ValueHashmapHandle handle, collection_key_t key, unsigned long* out)); |
| 42 | + |
| 43 | +// Erases a key from a u32 -> u32 hashmap. Does nothing if the key doesn't exist in the hashmap. |
| 44 | +// Returns 1 if the key was erased (i.e. it existed in the map), otherwise returns 0. |
| 45 | +RECOMP_IMPORT("*", int recomputil_u32_value_hashmap_erase(U32ValueHashmapHandle handle, collection_key_t key)); |
| 46 | + |
| 47 | +// Gets the size of a u32 -> u32 hashmap. |
| 48 | +// Returns the number of elements in the map. |
| 49 | +RECOMP_IMPORT("*", unsigned long recomputil_u32_value_hashmap_size(U32ValueHashmapHandle handle)); |
| 50 | + |
| 51 | +////////////////////////// |
| 52 | +// u32 -> data hashmaps // |
| 53 | +////////////////////////// |
| 54 | + |
| 55 | +typedef unsigned long U32MemoryHashmapHandle; |
| 56 | + |
| 57 | +// Creates a hashmap that maps u32 keys to data of a given element size. |
| 58 | +// Returns the handle for that hashmap. |
| 59 | +RECOMP_IMPORT("*", U32MemoryHashmapHandle recomputil_create_u32_memory_hashmap(unsigned long element_size)); |
| 60 | + |
| 61 | +// Destroys a u32 -> data hashmap. |
| 62 | +RECOMP_IMPORT("*", void recomputil_destroy_u32_memory_hashmap(U32MemoryHashmapHandle handle)); |
| 63 | + |
| 64 | +// Checks if a u32 -> data hashmap contains the given key. |
| 65 | +// Returns 1 if the key exists in the map, otherwise returns 0. |
| 66 | +RECOMP_IMPORT("*", int recomputil_u32_memory_hashmap_contains(U32MemoryHashmapHandle handle, collection_key_t key)); |
| 67 | + |
| 68 | +// Creates an element in a u32 -> data hashmap with the given key. Does nothing if the key already exists. |
| 69 | +// Returns 1 if the element was created (i.e. the key did not already existed), otherwise returns 0. |
| 70 | +RECOMP_IMPORT("*", int recomputil_u32_memory_hashmap_create(U32MemoryHashmapHandle handle, collection_key_t key)); |
| 71 | + |
| 72 | +// Attempts to retrieve a value from a u32 -> data hashmap. |
| 73 | +// Returns the element's pointer if the key exists in the map, otherwise returns null. |
| 74 | +RECOMP_IMPORT("*", void* recomputil_u32_memory_hashmap_get(U32MemoryHashmapHandle handle, collection_key_t key)); |
| 75 | + |
| 76 | +// Erases a key from a u32 -> data hashmap. Does nothing if the key doesn't exist in the hashmap. |
| 77 | +// Returns 1 if the key was erased (i.e. it existed in the map), otherwise returns 0. |
| 78 | +RECOMP_IMPORT("*", int recomputil_u32_memory_hashmap_erase(U32MemoryHashmapHandle handle, collection_key_t key)); |
| 79 | + |
| 80 | +// Gets the size of a u32 -> data hashmap. |
| 81 | +// Returns the number of elements in the map. |
| 82 | +RECOMP_IMPORT("*", unsigned long recomputil_u32_memory_hashmap_size(U32MemoryHashmapHandle handle)); |
| 83 | + |
| 84 | +////////////////// |
| 85 | +// u32 hashsets // |
| 86 | +////////////////// |
| 87 | + |
| 88 | +typedef unsigned long U32HashsetHandle; |
| 89 | + |
| 90 | +// Creates a hashset of u32 keys. |
| 91 | +// Returns the handle for that hashset. |
| 92 | +RECOMP_IMPORT("*", U32HashsetHandle recomputil_create_u32_hashset()); |
| 93 | + |
| 94 | +// Destroys a u32 hashset. |
| 95 | +RECOMP_IMPORT("*", void recomputil_destroy_u32_hashset(U32HashsetHandle handle)); |
| 96 | + |
| 97 | +// Checks if a u32 hashset contains the given key. |
| 98 | +// Returns 1 if the key exists in the set, otherwise returns 0. |
| 99 | +RECOMP_IMPORT("*", int recomputil_u32_hashset_contains(U32HashsetHandle handle, collection_key_t key)); |
| 100 | + |
| 101 | +// Inserts a key into a u32 hashset. |
| 102 | +// Returns 1 if the key was inserted (i.e. it did not exist in the set), otherwise returns 0. |
| 103 | +RECOMP_IMPORT("*", int recomputil_u32_hashset_insert(U32HashsetHandle handle, collection_key_t key)); |
| 104 | + |
| 105 | +// Erases a key from a u32 hashset. |
| 106 | +// Returns 1 if the key was erased (i.e. it exited in the set), otherwise returns 0. |
| 107 | +RECOMP_IMPORT("*", int recomputil_u32_hashset_erase(U32HashsetHandle handle, collection_key_t key)); |
| 108 | + |
| 109 | +// Gets the size of a u32 hashset. |
| 110 | +// Returns the number of elements in the set. |
| 111 | +RECOMP_IMPORT("*", unsigned long recomputil_u32_hashset_size(U32HashsetHandle handle)); |
| 112 | + |
| 113 | +////////////////// |
| 114 | +// u32 slotmaps // |
| 115 | +////////////////// |
| 116 | + |
| 117 | +typedef unsigned long U32SlotmapHandle; |
| 118 | + |
| 119 | +// Creates a slotmap with u32 elements. |
| 120 | +// Returns the handle for that slotmap. |
| 121 | +RECOMP_IMPORT("*", U32SlotmapHandle recomputil_create_u32_slotmap()); |
| 122 | + |
| 123 | +// Destroys a u32 slotmap. |
| 124 | +RECOMP_IMPORT("*", void recomputil_destroy_u32_slotmap(U32SlotmapHandle handle)); |
| 125 | + |
| 126 | +// Checks if a u32 slotmap contains the given key. |
| 127 | +// Returns 1 if the key exists in the map, otherwise returns 0. |
| 128 | +RECOMP_IMPORT("*", int recomputil_u32_slotmap_contains(U32SlotmapHandle handle, collection_key_t key)); |
| 129 | + |
| 130 | +// Creates an element in a u32 slotmap. |
| 131 | +// Returns the created element's key. |
| 132 | +RECOMP_IMPORT("*", collection_key_t recomputil_u32_slotmap_create(U32SlotmapHandle handle)); |
| 133 | + |
| 134 | +// Attempts to retrieve a value from a u32 slotmap. |
| 135 | +// Returns 1 if the key exists in the map and writes the element's value to *out, otherwise returns 0 and does not modify the contents in *out. |
| 136 | +RECOMP_IMPORT("*", int recomputil_u32_slotmap_get(U32SlotmapHandle handle, collection_key_t key, unsigned long* out)); |
| 137 | + |
| 138 | +// Attempts to set a value in a u32 slotmap. The value is not assigned if the key does not exist. |
| 139 | +// Returns 1 if the key existed, otherwise returns 0. |
| 140 | +RECOMP_IMPORT("*", int recomputil_u32_slotmap_set(U32SlotmapHandle handle, collection_key_t key, unsigned long value)); |
| 141 | + |
| 142 | +// Erases a key from a u32 slotmap. |
| 143 | +// Returns 1 if the key was erased (i.e. it exited in the map), otherwise returns 0. |
| 144 | +RECOMP_IMPORT("*", int recomputil_u32_slotmap_erase(U32SlotmapHandle handle, collection_key_t key)); |
| 145 | + |
| 146 | +// Gets the size of a u32 slotmap. |
| 147 | +// Returns the number of elements in the map. |
| 148 | +RECOMP_IMPORT("*", unsigned long recomputil_u32_slotmap_size(U32SlotmapHandle handle)); |
| 149 | + |
| 150 | +/////////////////// |
| 151 | +// data slotmaps // |
| 152 | +/////////////////// |
| 153 | + |
| 154 | +typedef unsigned long MemorySlotmapHandle; |
| 155 | + |
| 156 | +// Creates a slotmap with data elements of a given element size. |
| 157 | +// Returns the handle for that slotmap. |
| 158 | +RECOMP_IMPORT("*", MemorySlotmapHandle recomputil_create_memory_slotmap(unsigned long element_size)); |
| 159 | + |
| 160 | +// Destroys a memory slotmap. |
| 161 | +RECOMP_IMPORT("*", void recomputil_destroy_memory_slotmap(MemorySlotmapHandle handle)); |
| 162 | + |
| 163 | +// Checks if a memory slotmap contains the given key. |
| 164 | +// Returns 1 if the key exists in the map, otherwise returns 0. |
| 165 | +RECOMP_IMPORT("*", int recomputil_memory_slotmap_contains(MemorySlotmapHandle handle, collection_key_t key)); |
| 166 | + |
| 167 | +// Creates an element in a memory slotmap. |
| 168 | +// Returns the created element's key. |
| 169 | +RECOMP_IMPORT("*", collection_key_t recomputil_memory_slotmap_create(MemorySlotmapHandle handle)); |
| 170 | + |
| 171 | +// Attempts to retrieve an element from a u32 slotmap. |
| 172 | +// Returns 1 if the key exists in the map and writes the element's pointer to *out, otherwise returns 0 and does not modify the contents in *out. |
| 173 | +RECOMP_IMPORT("*", int recomputil_memory_slotmap_get(MemorySlotmapHandle handle, collection_key_t key, void** out)); |
| 174 | + |
| 175 | +// Erases a key from a memory slotmap. |
| 176 | +// Returns 1 if the key was erased (i.e. it exited in the map), otherwise returns 0. |
| 177 | +RECOMP_IMPORT("*", int recomputil_memory_slotmap_erase(MemorySlotmapHandle handle, collection_key_t key)); |
| 178 | + |
| 179 | +// Gets the size of a memory slotmap. |
| 180 | +// Returns the number of elements in the map. |
| 181 | +RECOMP_IMPORT("*", unsigned long recomputil_memory_slotmap_size(MemorySlotmapHandle handle)); |
| 182 | + |
| 183 | +#endif |
0 commit comments