Ruby 4.1.0dev (2026-09-07 revision b57404b461ba8bf34e802d86b0db78388216e182)
id_table.h (b57404b461ba8bf34e802d86b0db78388216e182)
1#ifndef RUBY_ID_TABLE_H
2#define RUBY_ID_TABLE_H 1
3#include "ruby/internal/config.h"
4#include <stddef.h>
5#include "ruby/ruby.h"
6
7struct rb_id_table {
8 int capa;
9 int num;
10 int used;
11 /* The table body is a single buffer laid out as:
12 *
13 * [VALUE values[capa] | id_key_t keys[capa] | collision bitmap]
14 *
15 * where the collision bitmap uses one mark bit per slot. */
16 void *buf;
17};
18
19/* compatible with ST_* */
20enum rb_id_table_iterator_result {
21 ID_TABLE_CONTINUE = ST_CONTINUE,
22 ID_TABLE_STOP = ST_STOP,
23 ID_TABLE_DELETE = ST_DELETE,
24 ID_TABLE_REPLACE = ST_REPLACE,
25 ID_TABLE_ITERATOR_RESULT_END
26};
27
28struct rb_id_table *rb_id_table_create(size_t size);
29struct rb_id_table *rb_id_table_init(struct rb_id_table *tbl, size_t capa);
30
31void rb_id_table_free(struct rb_id_table *tbl);
32void rb_id_table_free_items(struct rb_id_table *tbl);
33void rb_id_table_clear(struct rb_id_table *tbl);
34
35size_t rb_id_table_memsize(const struct rb_id_table *tbl);
36
37int rb_id_table_insert(struct rb_id_table *tbl, ID id, VALUE val);
38int rb_id_table_lookup(struct rb_id_table *tbl, ID id, VALUE *valp);
39int rb_id_table_delete(struct rb_id_table *tbl, ID id);
40
41typedef enum rb_id_table_iterator_result rb_id_table_update_value_callback_func_t(VALUE *val, void *data, int existing);
42typedef enum rb_id_table_iterator_result rb_id_table_foreach_func_t(ID id, VALUE val, void *data);
43typedef enum rb_id_table_iterator_result rb_id_table_foreach_values_func_t(VALUE val, void *data);
44void rb_id_table_foreach(struct rb_id_table *tbl, rb_id_table_foreach_func_t *func, void *data);
45void rb_id_table_foreach_values(struct rb_id_table *tbl, rb_id_table_foreach_values_func_t *func, void *data);
46void rb_id_table_foreach_values_with_replace(struct rb_id_table *tbl, rb_id_table_foreach_values_func_t *func, rb_id_table_update_value_callback_func_t *replace, void *data);
47
48VALUE rb_managed_id_table_create(const rb_data_type_t *type, size_t capa);
49VALUE rb_managed_id_table_new(size_t capa);
50VALUE rb_managed_id_table_dup(VALUE table);
51int rb_managed_id_table_insert(VALUE table, ID id, VALUE val);
52int rb_managed_id_table_lookup(VALUE table, ID id, VALUE *valp);
53size_t rb_managed_id_table_size(VALUE table);
54void rb_managed_id_table_foreach(VALUE table, rb_id_table_foreach_func_t *func, void *data);
55void rb_managed_id_table_foreach_values(VALUE table, rb_id_table_foreach_values_func_t *func, void *data);
56int rb_managed_id_table_delete(VALUE table, ID id);
57
58extern const rb_data_type_t rb_managed_id_table_type;
59
60VALUE rb_marked_id_table_new(size_t capa);
61int rb_marked_id_table_insert(VALUE table, ID id, VALUE val);
62VALUE rb_marked_id_table_dup(VALUE table);
63
64// alisases
65#define rb_marked_id_table_size rb_managed_id_table_size
66#define rb_marked_id_table_lookup rb_managed_id_table_lookup
67#define rb_marked_id_table_foreach rb_managed_id_table_foreach
68#define rb_marked_id_table_foreach_values rb_managed_id_table_foreach_values
69
70RUBY_SYMBOL_EXPORT_BEGIN
71size_t rb_id_table_size(const struct rb_id_table *tbl);
72RUBY_SYMBOL_EXPORT_END
73
74#endif /* RUBY_ID_TABLE_H */
int capa
Designed capacity of the buffer.
Definition io.h:11
VALUE type(ANYARGS)
ANYARGS-ed function type.
This is the struct that holds necessary info for a struct.
Definition rtypeddata.h:238
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40