LuaHashMap
1.0.0
|
Functions | |
LuaHashMap * | LuaHashMap_Create (void) |
Creates a new instance of a hash table. | |
LuaHashMap * | LuaHashMap_CreateWithAllocator (lua_Alloc the_allocator, void *user_data) |
Creates a new instance of a hash table with a custom allocator. | |
LuaHashMap * | LuaHashMap_CreateWithSizeHints (int number_of_array_elements, int number_of_hash_elements) |
Creates a new instance of a hash table with a suggested starting size. | |
LuaHashMap * | LuaHashMap_CreateWithAllocatorAndSizeHints (lua_Alloc the_allocator, void *user_data, int number_of_array_elements, int number_of_hash_elements) |
Creates a new instance of a hash table with a custom allocator and a suggested starting size. | |
LuaHashMap * | LuaHashMap_CreateShare (LuaHashMap *original_hash_map) |
Special Memory Optimization: Allows you to create new LuaHashMaps from an existing one which will share the same lua_State under the hood. | |
LuaHashMap * | LuaHashMap_CreateShareWithSizeHints (LuaHashMap *original_hash_map, int number_of_array_elements, int number_of_hash_elements) |
Just like LuaHashMap_CreateShare, except it allows you to pre-size the hash map. | |
LuaHashMap * | LuaHashMap_CreateShareFromLuaState (lua_State *lua_state) |
Special Memory Optimization: Allows you to create new LuaHashMaps from an existing lua_State. | |
LuaHashMap * | LuaHashMap_CreateShareFromLuaStateWithAllocatorAndSizeHints (lua_State *lua_state, lua_Alloc the_allocator, void *user_data, int number_of_array_elements, int number_of_hash_elements) |
Just like LuaHashMap_CreateShareFromLuaState but lets you specify your own allocator and pre-size hints. | |
LuaHashMap * | LuaHashMap_CreateShareFromLuaStateWithSizeHints (lua_State *lua_state, int number_of_array_elements, int number_of_hash_elements) |
Just like LuaHashMap_CreateShareFromLuaState but lets you specify your own pre-size hints. | |
void | LuaHashMap_Free (LuaHashMap *hash_map) |
Frees a LuaHashMap instance. | |
void | LuaHashMap_FreeShare (LuaHashMap *hash_map) |
Frees a LuaHashMap instance (intended for those created with LuaHashMap_CreateShare or LuaHashMap_CreateShareFromLuaState). | |
LuaHashMap* LuaHashMap_Create | ( | void | ) |
Creates a new instance of a hash table.
This creates a new instance of a LuaHashMap. You will use this as your opaque LuaHashMap "object" for all the per-instance hash map operations.
LuaHashMap* LuaHashMap_CreateShare | ( | LuaHashMap * | original_hash_map | ) |
Special Memory Optimization: Allows you to create new LuaHashMaps from an existing one which will share the same lua_State under the hood.
Currently, every LuaHashMap instance created with the Create family of functions (excluding CreateShare) will create a brand new virtual machine (lua_State*). My measurements of a new lua_State instance seem to take about 4-5KB on 64-bit Mac. This function was designed to let you avoid incuring that cost by letting you reuse another LuaHashMap's lua_State. But for all other purposes (besides freeing), your hash map instances will appear completely independent and the API calls you make don't change in any other way.
original_hash_map | The hash map you want to reuse a lua_State from. |
LuaHashMap* LuaHashMap_CreateShareFromLuaState | ( | lua_State * | lua_state | ) |
Special Memory Optimization: Allows you to create new LuaHashMaps from an existing lua_State.
This will create a new LuaHashMap instance from a pre-existing lua_State with the intention of saving memory. Currently, every LuaHashMap instance created with the Create family of functions (excluding CreateShare) will create a brand new virtual machine (lua_State*). My measurements of a new lua_State instance seem to take about 4-5KB on 64-bit Mac. This function was designed to let you avoid incuring that cost by letting you reuse a lua_State that you may already have for other purposes. But for all other purposes (besides freeing), your hash map instances will appear completely independent and the API calls you make don't change in any other way. LuaHashMap uses the Lua registry with luaL_ref/luaL_unref (to get a unique table), so it should not collide or intefere with anything you are doing in your Lua state.
lua_state | A lua_State you wish to use/share with your hash map |
LuaHashMap* LuaHashMap_CreateShareFromLuaStateWithAllocatorAndSizeHints | ( | lua_State * | lua_state, |
lua_Alloc | the_allocator, | ||
void * | user_data, | ||
int | number_of_array_elements, | ||
int | number_of_hash_elements | ||
) |
Just like LuaHashMap_CreateShareFromLuaState but lets you specify your own allocator and pre-size hints.
lua_state | A lua_State you wish to use/share with your hash map |
the_allocator | The custom memory allocator you want to provide. |
user_data | A user data/context pointer to go with the allocator.* |
number_of_array_elements | Lua tables double as both arrays and hash tables in Lua. As such, this parameter let's you pre-size the number of array elements. Most users of this library will probably use 0 because they don't need the array part. |
number_of_hash_elements | This parameter is used to pre-size the number of hash buckets. |
LuaHashMap* LuaHashMap_CreateShareFromLuaStateWithSizeHints | ( | lua_State * | lua_state, |
int | number_of_array_elements, | ||
int | number_of_hash_elements | ||
) |
Just like LuaHashMap_CreateShareFromLuaState but lets you specify your own pre-size hints.
lua_state | A lua_State you wish to use/share with your hash map |
number_of_array_elements | Lua tables double as both arrays and hash tables in Lua. As such, this parameter let's you pre-size the number of array elements. Most users of this library will probably use 0 because they don't need the array part. |
number_of_hash_elements | This parameter is used to pre-size the number of hash buckets. |
LuaHashMap* LuaHashMap_CreateShareWithSizeHints | ( | LuaHashMap * | original_hash_map, |
int | number_of_array_elements, | ||
int | number_of_hash_elements | ||
) |
Just like LuaHashMap_CreateShare, except it allows you to pre-size the hash map.
original_hash_map | The hash map you want to reuse a lua_State from. |
number_of_array_elements | Lua tables double as both arrays and hash tables in Lua. As such, this parameter let's you pre-size the number of array elements. Most users of this library will probably use 0 because they don't need the array part. |
number_of_hash_elements | This parameter is used to pre-size the number of hash buckets. |
LuaHashMap* LuaHashMap_CreateWithAllocator | ( | lua_Alloc | the_allocator, |
void * | user_data | ||
) |
Creates a new instance of a hash table with a custom allocator.
This creates a new instance of a LuaHashMap with a custom allocator. The allocator adopts the lua_Alloc model as defined by Lua.
You will use this as your opaque LuaHashMap "object" for all the per-instance hash map operations.
the_allocator | The custom memory allocator you want to provide. |
user_data | A user data/context pointer to go with the allocator. |
LuaHashMap* LuaHashMap_CreateWithAllocatorAndSizeHints | ( | lua_Alloc | the_allocator, |
void * | user_data, | ||
int | number_of_array_elements, | ||
int | number_of_hash_elements | ||
) |
Creates a new instance of a hash table with a custom allocator and a suggested starting size.
This creates a new instance of a LuaHashMap with a custom allocator. The allocator adopts the lua_Alloc model as defined by Lua. This also let's you hint Lua on how many elements to pre-size the hash table for. If you know the size your hash is going to grow to, this you should specify this number as a performance optimization. Growing the hash table after running out of buckets is generally an expensive operation so pre-sizing it can help.
You will use this as your opaque LuaHashMap "object" for all the per-instance hash map operations.
the_allocator | The custom memory allocator you want to provide. |
user_data | A user data/context pointer to go with the allocator.* |
number_of_array_elements | Lua tables double as both arrays and hash tables in Lua. As such, this parameter let's you pre-size the number of array elements. Most users of this library will probably use 0 because they don't need the array part. |
number_of_hash_elements | This parameter is used to pre-size the number of hash buckets. |
LuaHashMap* LuaHashMap_CreateWithSizeHints | ( | int | number_of_array_elements, |
int | number_of_hash_elements | ||
) |
Creates a new instance of a hash table with a suggested starting size.
This creates a new instance of a LuaHashMap with a hint to Lua on how many elements to pre-size the hash table for. If you know the size your hash is going to grow to, this you should specify this number as a performance optimization. Growing the hash table after running out of buckets is generally an expensive operation so pre-sizing it can help.
You will use this as your opaque LuaHashMap "object" for all the per-instance hash map operations.
number_of_array_elements | Lua tables double as both arrays and hash tables in Lua. As such, this parameter let's you pre-size the number of array elements. Most users of this library will probably use 0 because they don't need the array part. |
number_of_hash_elements | This parameter is used to pre-size the number of hash buckets. |
void LuaHashMap_Free | ( | LuaHashMap * | hash_map | ) |
Frees a LuaHashMap instance.
This releases the memory associated with the LuaHashMap.
hash_map | The LuaHashMap instance to operate on. |
void LuaHashMap_FreeShare | ( | LuaHashMap * | hash_map | ) |
Frees a LuaHashMap instance (intended for those created with LuaHashMap_CreateShare or LuaHashMap_CreateShareFromLuaState).
This releases the memory associated with the LuaHashMap that were created with LuaHashMap_CreateShare or LuaHashMap_CreateShareFromLuaState.
hash_map | The LuaHashMap instance to operate on. |