Ruby 4.1.0dev (2026-04-04 revision 892991bdc1a5068d74a8597cd0ccf3092afffabf)
id_table.h (892991bdc1a5068d74a8597cd0ccf3092afffabf)
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_item;
8
9struct rb_id_table {
10 int capa;
11 int num;
12 int used;
13 struct rb_id_item *items;
14};
15
16/* compatible with ST_* */
17enum rb_id_table_iterator_result {
18 ID_TABLE_CONTINUE = ST_CONTINUE,
19 ID_TABLE_STOP = ST_STOP,
20 ID_TABLE_DELETE = ST_DELETE,
21 ID_TABLE_REPLACE = ST_REPLACE,
22 ID_TABLE_ITERATOR_RESULT_END
23};
24
25struct rb_id_table *rb_id_table_create(size_t size);
26struct rb_id_table *rb_id_table_init(struct rb_id_table *tbl, size_t capa);
27
28void rb_id_table_free(struct rb_id_table *tbl);
29void rb_id_table_free_items(struct rb_id_table *tbl);
30void rb_id_table_clear(struct rb_id_table *tbl);
31
32size_t rb_id_table_memsize(const struct rb_id_table *tbl);
33
34int rb_id_table_insert(struct rb_id_table *tbl, ID id, VALUE val);
35int rb_id_table_lookup(struct rb_id_table *tbl, ID id, VALUE *valp);
36int rb_id_table_delete(struct rb_id_table *tbl, ID id);
37
38typedef enum rb_id_table_iterator_result rb_id_table_update_value_callback_func_t(VALUE *val, void *data, int existing);
39typedef enum rb_id_table_iterator_result rb_id_table_foreach_func_t(ID id, VALUE val, void *data);
40typedef enum rb_id_table_iterator_result rb_id_table_foreach_values_func_t(VALUE val, void *data);
41void rb_id_table_foreach(struct rb_id_table *tbl, rb_id_table_foreach_func_t *func, void *data);
42void rb_id_table_foreach_values(struct rb_id_table *tbl, rb_id_table_foreach_values_func_t *func, void *data);
43void 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);
44
45VALUE rb_managed_id_table_create(const rb_data_type_t *type, size_t capa);
46VALUE rb_managed_id_table_new(size_t capa);
47VALUE rb_managed_id_table_dup(VALUE table);
48int rb_managed_id_table_insert(VALUE table, ID id, VALUE val);
49int rb_managed_id_table_lookup(VALUE table, ID id, VALUE *valp);
50size_t rb_managed_id_table_size(VALUE table);
51void rb_managed_id_table_foreach(VALUE table, rb_id_table_foreach_func_t *func, void *data);
52void rb_managed_id_table_foreach_values(VALUE table, rb_id_table_foreach_values_func_t *func, void *data);
53int rb_managed_id_table_delete(VALUE table, ID id);
54
55extern const rb_data_type_t rb_managed_id_table_type;
56
57RUBY_SYMBOL_EXPORT_BEGIN
58size_t rb_id_table_size(const struct rb_id_table *tbl);
59RUBY_SYMBOL_EXPORT_END
60
61#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:229
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