Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
map.c File Reference

Simple string-keyed map implementation backing VAL_MAP Values. More...

#include "value.h"
#include <stdlib.h>
#include <string.h>
Include dependency graph for map.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Map

Typedefs

typedef struct Map Map

Functions

Value make_map_empty (void)
 Construct a new empty map Value.
int map_set (Value *vm, const char *key, Value v)
 Insert or replace a key in the map.
int map_get_copy (const Value *vm, const char *key, Value *out)
 Look up a key and copy the stored value into out.
int map_has (const Value *vm, const char *key)
 Check whether the map contains the specified key.
Value map_keys_array (const Value *vm)
 Return all map keys as an array of strings.
Value map_values_array (const Value *vm)
 Return all map values as an array (deep-copied).

Detailed Description

Simple string-keyed map implementation backing VAL_MAP Values.

Definition in file map.c.

Typedef Documentation

◆ Map

typedef struct Map Map

Function Documentation

◆ make_map_empty()

Value make_map_empty(void)

Construct a new empty map Value.

Allocates an internal Map structure with refcount=1 and zero capacity.

Returns
A Value of type VAL_MAP on success, or VAL_NIL on allocation failure.

Definition at line 35 of file map.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ map_get_copy()

int map_get_copy(const Value *vm,
const char *key,
Value *out )

Look up a key and copy the stored value into out.

The returned value is a deep copy; caller owns it and must free it.

Parameters
vmSource map Value (VAL_MAP).
keyKey to search for.
outOutput pointer to receive a copy; may be NULL to only test presence.
Returns
1 if found (and out filled if non-NULL), 0 otherwise.

Definition at line 112 of file map.c.

Here is the call graph for this function:

◆ map_has()

int map_has(const Value *vm,
const char *key )

Check whether the map contains the specified key.

Parameters
vmMap Value (VAL_MAP).
keyKey to search for.
Returns
1 if present, 0 if absent or on invalid input.

Definition at line 130 of file map.c.

◆ map_keys_array()

Value map_keys_array(const Value *vm)

Return all map keys as an array of strings.

Ownership: Caller must free the returned Value with free_value().

Parameters
vmMap Value (VAL_MAP).
Returns
Array Value of keys; empty array if vm is not a map or is empty.

Definition at line 147 of file map.c.

Here is the call graph for this function:

◆ map_set()

int map_set(Value *vm,
const char *key,
Valuev )

Insert or replace a key in the map.

On success, ownership of v transfers into the map. On failure, v is freed.

Parameters
vmTarget Value of type VAL_MAP.
keyNUL-terminated key string (copied into the map).
vValue to store; consumed on success.
Returns
1 on success, 0 on error (type mismatch, OOM, or NULL params).

Definition at line 79 of file map.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ map_values_array()

Value map_values_array(const Value *vm)

Return all map values as an array (deep-copied).

Ownership: Caller must free the returned Value with free_value().

Parameters
vmMap Value (VAL_MAP).
Returns
Array Value of values; empty array if vm is not a map or is empty.

Definition at line 171 of file map.c.

Here is the call graph for this function: