Cthulhu  0.2.10
Cthulhu compiler collection
map.c File Reference
#include "std/map.h"
#include "base/panic.h"
#include "arena/arena.h"
#include "std/str.h"
#include "std/vector.h"
#include "std/typed/vector.h"
#include "common.h"
Include dependency graph for map.c:

Go to the source code of this file.

Data Structures

struct  bucket_t
 a single node in a map More...
 

Macros

#define MAP_LOAD_FACTOR   (90)
 
#define MAP_FOREACH_APPLY(self, item, ...)
 

Functions

STA_DECL void map_init (map_t *map, size_t size, hash_info_t info, arena_t *arena)
 
STA_DECL map_t map_make (size_t size, hash_info_t info, arena_t *arena)
 create a new map on the stack More...
 
STA_DECL map_tmap_new (size_t size, hash_info_t info, arena_t *arena)
 create a new map on the heap More...
 
STA_DECL vector_tmap_values (map_t *map)
 collect all the values from a map into a vector More...
 
STA_DECL typevec_tmap_entries (map_t *map)
 collect all key-value pairs in a map into a vector returns a typevec_t<map_entry_t> More...
 
STA_DECL size_t map_count (const map_t *map)
 get the number of key-value pairs in a map More...
 
STA_DECL CT_HOTFN void map_set (map_t *map, const void *key, void *value)
 set a key-value pair in a map More...
 
STA_DECL CT_HOTFN void * map_get (const map_t *map, const void *key)
 get a value from a map More...
 
STA_DECL CT_HOTFN void * map_get_default (const map_t *map, const void *key, void *other)
 get a value from a map or a default value More...
 
STA_DECL bool map_contains (const map_t *map, const void *key)
 check if a map contains a key More...
 
STA_DECL bool map_delete (map_t *map, const void *key)
 delete a key-value pair from a map More...
 
STA_DECL void map_reset (map_t *map)
 clear all key-value pairs from a map More...
 
STA_DECL map_iter_t map_iter (const map_t *map)
 create a new map iterator More...
 
STA_DECL CT_NOALIAS map_entry_t map_next (map_iter_t *iter)
 get the next key-value pair from a map iterator More...
 
STA_DECL bool map_next_pair (map_iter_t *iter, const void **key, void **value)
 get the next key-value pair from a map iterator returns the values via out parameters for ease of use this also returns false if the iterator has no more elements this is intended to be used via CTU_MAP_NEXT for more idiomatic usage More...
 
STA_DECL CT_PUREFN bool map_has_next (const map_iter_t *iter)
 check if a map iterator has more elements More...
 

Variables

const map_t kEmptyMap
 an empty map More...
 

Macro Definition Documentation

◆ MAP_FOREACH_APPLY

#define MAP_FOREACH_APPLY (   self,
  item,
  ... 
)
Value:
do \
{ \
for (size_t i = 0; i < self->size; i++) \
{ \
bucket_t *item = &self->data[i]; \
while (item && item->key) \
{ \
__VA_ARGS__; \
item = item->next; \
} \
} \
} while (0)

Definition at line 122 of file map.c.

◆ MAP_LOAD_FACTOR

#define MAP_LOAD_FACTOR   (90)

Definition at line 17 of file map.c.

Function Documentation

◆ map_init()

STA_DECL void map_init ( map_t map,
size_t  size,
hash_info_t  info,
arena_t arena 
)

Definition at line 81 of file map.c.