Serene Runtime 1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
maps.h File Reference
Include dependency graph for maps.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  srn_map_t
 A persistent, immutable map. More...
 

Typedefs

typedef struct srn_map_t srn_map_t
 A persistent, immutable map.
 

Functions

srn_value_tsrn_map_empty (srn_context_t *ctx, srn_metadata_t *metadata)
 
srn_value_tsrn_map_assoc (srn_context_t *ctx, srn_metadata_t *metadata, srn_value_t *map, srn_value_t *key, srn_value_t *value)
 

Typedef Documentation

◆ srn_map_t

typedef struct srn_map_t srn_map_t

A persistent, immutable map.

Backed by the CHAMT in serene/rt/impl/hashmap.h. Keys and values are both srn_value_t*.

Function Documentation

◆ srn_map_assoc()

srn_value_t * srn_map_assoc ( srn_context_t * ctx,
srn_metadata_t * metadata,
srn_value_t * map,
srn_value_t * key,
srn_value_t * value )

Definition at line 66 of file maps.c.

67 {
68 PANIC_IF_NULL(ctx);
69 PANIC_IF_NULL(map);
70 PANIC_IF_NULL(key);
71 PANIC_IF_NULL(value);
72
73 if (!IS_A(map, VMap)) {
74 return srn_errors_make_error(ctx, metadata, ABSURD, "expected a map");
75 }
76
77 hmap_key_t *k = hmap_make_key(ctx, key, sizeof(*key));
78
79 srn_map_t *old = AS_MAP(map);
80 srn_map_t *neu = ALLOC(ctx, srn_map_t);
81
82 neu->inner = value_map.insert(&value_map, ctx, &old->inner, k, value);
83 return srn_value_make(ctx, VMap, metadata, (void *)neu);
84}
#define ALLOC(ctx, T)
Definition context.h:82
srn_value_t * srn_value_make(srn_context_t *ctx, srn_value_tag_t tag, srn_metadata_t *metadata, void *payload)
Creates a new serene value.
Definition core.c:24
@ VMap
Definition core.h:126
#define AS_MAP(value_ref)
Definition core.h:177
#define IS_A(value_ref, field)
Definition core.h:162
@ ABSURD
Definition errors.h:45
hmap_key_t * hmap_make_key(srn_context_t *ctx, void *data, size_t len)
Create a new key out of the given data, with the given len.
Definition hashmap.c:627
static const hmap_control_t value_map
Definition maps.c:52
Note: For key equality we use the memcpy function.
Definition hashmap.h:66
A persistent, immutable map.
Definition maps.h:29
hmap_t inner
Definition maps.h:30
#define PANIC_IF_NULL(ptr)
Definition utils.h:64
Here is the call graph for this function:

◆ srn_map_empty()

srn_value_t * srn_map_empty ( srn_context_t * ctx,
srn_metadata_t * metadata )

Definition at line 59 of file maps.c.

59 {
60 PANIC_IF_NULL(ctx);
61 srn_map_t *m = ALLOC(ctx, srn_map_t);
62 m->inner = hmap_empty(ctx);
63 return srn_value_make(ctx, VMap, metadata, (void *)m);
64}
hmap_t hmap_empty(srn_context_t *ctx)
Create, initialize and return a new hashmap.
Definition hashmap.c:612
Here is the call graph for this function: