libsnobol4 1.0.2
High-performance SNOBOL4-style pattern matching library
Loading...
Searching...
No Matches
array.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7
23
24#include "snobol/snobol_attrs.h"
25#include <stdbool.h>
26#include <stddef.h>
27#include <stdint.h>
28
30#define ARRAY_INITIAL_CAPACITY 16
31
35typedef struct array_entry {
36 int32_t key;
37 char *value;
38 size_t value_len;
39 uint32_t hash;
40 bool active;
42
54
60SNOBOL_NODISCARD snobol_array_t *snobol_array_create(int32_t bounds_hint);
61
68
74
82SNOBOL_NODISCARD bool snobol_array_set(snobol_array_t *array, int32_t key,
83 const char *value);
84
92const char *snobol_array_get(const snobol_array_t *array, int32_t key);
93
102SNOBOL_NODISCARD bool snobol_array_set_ex(snobol_array_t *array, int32_t key,
103 const char *value, size_t value_len);
104
113const char *snobol_array_get_ex(const snobol_array_t *array, int32_t key,
114 size_t *out_len);
115
122bool snobol_array_has(const snobol_array_t *array, int32_t key);
123
130SNOBOL_NODISCARD bool snobol_array_delete(snobol_array_t *array, int32_t key);
131
137
144
151int32_t *snobol_array_keys(const snobol_array_t *array, size_t *out_count);
152
159char **snobol_array_values(const snobol_array_t *array, size_t *out_count);
160
161#ifdef __cplusplus
162}
163#endif
void snobol_array_release(snobol_array_t *array)
Release (decrement refcount) an array; frees when refcount reaches 0.
snobol_array_t * snobol_array_create(int32_t bounds_hint)
Create a new sparse array.
const char * snobol_array_get(const snobol_array_t *array, int32_t key)
Get the value at a given key.
const char * snobol_array_get_ex(const snobol_array_t *array, int32_t key, size_t *out_len)
Get the value at a given key (NUL-safe).
char ** snobol_array_values(const snobol_array_t *array, size_t *out_count)
Get all active values.
bool snobol_array_set(snobol_array_t *array, int32_t key, const char *value)
Set a value at the given key.
bool snobol_array_set_ex(snobol_array_t *array, int32_t key, const char *value, size_t value_len)
Set a value at the given key (NUL-safe byte-exact variant).
bool snobol_array_delete(snobol_array_t *array, int32_t key)
Delete the entry at a given key (marks as tombstone).
void snobol_array_clear(snobol_array_t *array)
Clear all entries from the array (resets to empty).
bool snobol_array_has(const snobol_array_t *array, int32_t key)
Check whether a key has an active entry.
size_t snobol_array_size(const snobol_array_t *array)
Return the number of active entries.
int32_t * snobol_array_keys(const snobol_array_t *array, size_t *out_count)
Get all active keys.
struct array_entry array_entry_t
A single entry in the sparse array.
snobol_array_t * snobol_array_retain(snobol_array_t *array)
Retain (increment refcount) an array.
struct snobol_array snobol_array_t
Sparse array state.
Portable function-attribute macros for SNOBOL4.
A single entry in the sparse array.
Definition array.h:35
size_t value_len
Definition array.h:38
bool active
Definition array.h:40
int32_t key
Definition array.h:36
uint32_t hash
Definition array.h:39
char * value
Definition array.h:37
Sparse array state.
Definition array.h:46
int32_t bounds_hint
Definition array.h:52
size_t tombstones
Definition array.h:50
array_entry_t * entries
Definition array.h:47
size_t capacity
Definition array.h:48
size_t size
Definition array.h:49
uint32_t refcount
Definition array.h:51