No Matches
Data Fields | Related Symbols
as_orderedmap Struct Reference

Detailed Description

A sorted array based implementation of as_map.

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

as_orderedmap_init(&map, 256);
AS_EXTERN as_orderedmap * as_orderedmap_init(as_orderedmap *map, uint32_t capacity)

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

AS_EXTERN as_orderedmap * as_orderedmap_new(uint32_t capacity)

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

AS_EXTERN void as_orderedmap_destroy(as_orderedmap *map)

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

static int as_stringmap_set_int64(as_map *m, const char *k, int64_t v)
static void as_map_destroy(as_map *map)
Definition as_map.h:254

The as_stringmap functions are simplified functions for using string key.

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


This orderedmap implementation is NOT threadsafe.

Internally, the orderedmap 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 orderedmap is still in use.

Further, the orderedmap does not increment ref-counts of the keys or values. However when an element is removed from the orderedmap, the orderedmap will call as_val_destroy() on both the key and value. And when the orderedmap 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 orderedmap without extra ref-counts, the caller is effectively handing off ownership of these objects to the orderedmap.

Definition at line 106 of file as_orderedmap.h.

#include "as_orderedmap.h"

+ Inheritance diagram for as_orderedmap:
+ Collaboration diagram for as_orderedmap:

Data Fields

uint32_t capacity
uint32_t count
uint32_t hold_count
uint32_t * hold_locations
- Data Fields inherited from as_map
uint32_t flags
const struct as_map_hooks_s * hooks
- Data Fields inherited from as_val
uint32_t count
bool free
as_val_t type

Related Symbols

(Note that these are not member symbols.)

AS_EXTERN int as_orderedmap_clear (as_orderedmap *map)
AS_EXTERN void as_orderedmap_destroy (as_orderedmap *map)
AS_EXTERN bool as_orderedmap_foreach (const as_orderedmap *map, as_map_foreach_callback callback, void *udata)
AS_EXTERN as_valas_orderedmap_get (const as_orderedmap *map, const as_val *key)
AS_EXTERN as_orderedmapas_orderedmap_init (as_orderedmap *map, uint32_t capacity)
AS_EXTERN as_orderedmapas_orderedmap_new (uint32_t capacity)
AS_EXTERN int as_orderedmap_remove (as_orderedmap *map, const as_val *key)
AS_EXTERN int as_orderedmap_set (as_orderedmap *map, const as_val *key, const as_val *val)
static void as_orderedmap_set_flags (as_orderedmap *map, uint32_t flags)
AS_EXTERN uint32_t as_orderedmap_size (const as_orderedmap *map)

Friends And Related Symbol Documentation

◆ as_orderedmap_clear()

AS_EXTERN int as_orderedmap_clear ( as_orderedmap * map)

Remove all entries from the map.

mapThe map.
0 on success. Otherwise an error occurred.

◆ as_orderedmap_destroy()

AS_EXTERN void as_orderedmap_destroy ( as_orderedmap * map)

Free the map and associated resources.

mapThe map to destroy.

◆ as_orderedmap_foreach()

AS_EXTERN bool as_orderedmap_foreach ( const as_orderedmap * map,
as_map_foreach_callback callback,
void * udata )

Call the callback function for each entry in the map.

mapThe map.
callbackThe function to call for each entry.
udataUser-data to be passed to the callback.
true if iteration completes fully. false if iteration was aborted.

◆ as_orderedmap_get()

AS_EXTERN as_val * as_orderedmap_get ( const as_orderedmap * map,
const as_val * key )

Get the value for specified key.

mapThe map.
keyThe key.
The value for the specified key. Otherwise NULL.

◆ as_orderedmap_init()

AS_EXTERN as_orderedmap * as_orderedmap_init ( as_orderedmap * map,
uint32_t capacity )

Initialize a stack allocated orderedmap.

mapThe map to initialize.
capacityThe number of entries (keys) to allocate for.
On success, the initialized map. Otherwise NULL.

◆ as_orderedmap_new()

AS_EXTERN as_orderedmap * as_orderedmap_new ( uint32_t capacity)

Creates a new map as an orderedmap.

capacityThe number of keys to allocate for.
On success, the new map. Otherwise NULL.

◆ as_orderedmap_remove()

AS_EXTERN int as_orderedmap_remove ( as_orderedmap * map,
const as_val * key )

Remove the entry specified by the key.

mapThe map to remove the entry from.
keyThe key of the entry to be removed.
0 on success. Otherwise an error occurred.

◆ as_orderedmap_set()

AS_EXTERN int as_orderedmap_set ( as_orderedmap * map,
const as_val * key,
const as_val * val )

Set the value for specified key.

mapThe map.
keyThe key.
valThe value for the given key.
0 on success. Otherwise an error occurred.

◆ as_orderedmap_set_flags()

static void as_orderedmap_set_flags ( as_orderedmap * map,
uint32_t flags )

Set map attributes.

Definition at line 291 of file as_orderedmap.h.

References AS_MAP_FLAGS_MASK, and as_map::flags.

◆ as_orderedmap_size()

AS_EXTERN uint32_t as_orderedmap_size ( const as_orderedmap * map)

Get the number of entries in the map.

mapThe map.
The number of entries in the map.

Field Documentation

◆ capacity

uint32_t as_orderedmap::capacity

Definition at line 110 of file as_orderedmap.h.

◆ count

uint32_t as_orderedmap::count

Definition at line 109 of file as_orderedmap.h.

◆ hold_count

uint32_t as_orderedmap::hold_count

Definition at line 113 of file as_orderedmap.h.

◆ hold_locations

uint32_t* as_orderedmap::hold_locations

Definition at line 115 of file as_orderedmap.h.

◆ hold_table

map_entry* as_orderedmap::hold_table

Definition at line 114 of file as_orderedmap.h.

◆ table

map_entry* as_orderedmap::table

Definition at line 111 of file as_orderedmap.h.

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