All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Fields | Related Functions
as_hashmap Struct Reference

Detailed Description

A hashtable based implementation of as_map.

To use the map, you can either initialize a stack allocated map, using as_hashmap_init():

as_hashmap_init(&map, 32);

Or you can create a new heap allocated map using as_hashmap_new():

When you are finished using the map, then you should release the map and associated resources, using as_hashmap_destroy():

The as_hashmap is a subtype of as_map. This allows you to alternatively use as_map functions, by typecasting as_hashmap to as_map.

The as_stringmap functions are simplified functions for using string key.

Each of the as_map functions proxy to the as_hashmap functions. So, calling as_map_destroy() is equivalent to calling as_hashmap_destroy().

Notes:

This hashmap implementation is NOT threadsafe.

Internally, the hashmap stores keys' and values' pointers - it does NOT copy the keys or values, so the caller must ensure these keys and values are not destroyed while the hashmap is still in use.

Further, the hashmap does not increment ref-counts of the keys or values. However when an element is removed from the hashmap, the hashmap will call as_val_destroy() on both the key and value. And when the hashmap is cleared or destroyed, as_val_destroy() will be called for all keys and values. Therefore if the caller inserts keys and values in the hashmap without extra ref-counts, the caller is effectively handing off ownership of these objects to the hashmap.

Definition at line 105 of file as_hashmap.h.

#include "as_hashmap.h"

+ Inheritance diagram for as_hashmap:
+ Collaboration diagram for as_hashmap:

Data Fields

uint32_t capacity_step
 
uint32_t count
 
uint32_t extra_capacity
 
as_hashmap_elementextras
 
uint32_t free_q
 
uint32_t insert_at
 
as_hashmap_elementtable
 
uint32_t table_capacity
 
- Data Fields inherited from as_map
uint32_t flags
 
struct as_map_hooks_s * hooks
 
- Data Fields inherited from as_val
cf_atomic32 count
 
bool free
 
enum as_val_t type
 

Related Functions

(Note that these are not member functions.)

int as_hashmap_clear (as_hashmap *map)
 
void as_hashmap_destroy (as_hashmap *map)
 
bool as_hashmap_foreach (const as_hashmap *map, as_map_foreach_callback callback, void *udata)
 
as_valas_hashmap_get (const as_hashmap *map, const as_val *key)
 
uint32_t as_hashmap_hashcode (const as_hashmap *map)
 
as_hashmapas_hashmap_init (as_hashmap *map, uint32_t buckets)
 
as_hashmapas_hashmap_new (uint32_t buckets)
 
int as_hashmap_remove (as_hashmap *map, const as_val *key)
 
int as_hashmap_set (as_hashmap *map, const as_val *key, const as_val *val)
 
uint32_t as_hashmap_size (const as_hashmap *map)
 

Friends And Related Function Documentation

int as_hashmap_clear ( as_hashmap map)
related

Remove all entries from the map.

Parameters
mapThe map.
Returns
0 on success. Otherwise an error occurred.
void as_hashmap_destroy ( as_hashmap map)
related

Free the map and associated resources.

Parameters
mapThe map to destroy.
bool as_hashmap_foreach ( const as_hashmap map,
as_map_foreach_callback  callback,
void *  udata 
)
related

Call the callback function for each entry in the map.

Parameters
mapThe map.
callbackThe function to call for each entry.
udataUser-data to be passed to the callback.
Returns
true if iteration completes fully. false if iteration was aborted.
as_val * as_hashmap_get ( const as_hashmap map,
const as_val key 
)
related

Get the value for specified key.

Parameters
mapThe map.
keyThe key.
Returns
The value for the specified key. Otherwise NULL.
uint32_t as_hashmap_hashcode ( const as_hashmap map)
related

The hash value of the map.

Parameters
mapThe map.
Returns
The hash value of the map.
as_hashmap * as_hashmap_init ( as_hashmap map,
uint32_t  buckets 
)
related

Initialize a stack allocated hashmap.

Parameters
mapThe map to initialize.
bucketsThe number of hash buckets to allocate.
Returns
On success, the initialized map. Otherwise NULL.
as_hashmap * as_hashmap_new ( uint32_t  buckets)
related

Creates a new map as a hashmap.

Parameters
bucketsThe number of hash buckets to allocate.
Returns
On success, the new map. Otherwise NULL.
int as_hashmap_remove ( as_hashmap map,
const as_val key 
)
related

Remove the entry specified by the key.

Parameters
mapThe map to remove the entry from.
keyThe key of the entry to be removed.
Returns
0 on success. Otherwise an error occurred.
int as_hashmap_set ( as_hashmap map,
const as_val key,
const as_val val 
)
related

Set the value for specified key.

Parameters
mapThe map.
keyThe key.
valThe value for the given key.
Returns
0 on success. Otherwise an error occurred.
uint32_t as_hashmap_size ( const as_hashmap map)
related

Get the number of entries in the map.

Parameters
mapThe map.
Returns
The number of entries in the map.

Field Documentation

uint32_t as_hashmap::capacity_step

The "extra" slots - elements go here when their key hash collides with that of an existing element's key.

Definition at line 130 of file as_hashmap.h.

uint32_t as_hashmap::count

Number of elements in the map.

Definition at line 117 of file as_hashmap.h.

uint32_t as_hashmap::extra_capacity

Definition at line 131 of file as_hashmap.h.

as_hashmap_element* as_hashmap::extras

Definition at line 132 of file as_hashmap.h.

uint32_t as_hashmap::free_q

Definition at line 134 of file as_hashmap.h.

uint32_t as_hashmap::insert_at

Definition at line 133 of file as_hashmap.h.

as_hashmap_element* as_hashmap::table

Definition at line 124 of file as_hashmap.h.

uint32_t as_hashmap::table_capacity

The "main" table - elements go here unless their key hash collides with that of an existing element's key.

Definition at line 123 of file as_hashmap.h.


The documentation for this struct was generated from the following file: