mruby/c VM Source Code master (2026/08/06)
Loading...
Searching...
No Matches
c_hash.h
Go to the documentation of this file.
1
14
15#ifndef MRBC_SRC_C_HASH_H_
16#define MRBC_SRC_C_HASH_H_
17
18/***** Feature test switches ************************************************/
19/***** System headers *******************************************************/
20//@cond
21#include <stdint.h>
22//@endcond
23
24/***** Local headers ********************************************************/
25#include "value.h"
26#include "c_array.h"
27#include "vm.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/***** Constat values *******************************************************/
34/***** Macros ***************************************************************/
35/***** Typedefs *************************************************************/
36//================================================================
42typedef struct RHash {
43 // (NOTE)
44 // Needs to be same members and order as RArray.
46
47 uint16_t data_size;
48 uint16_t n_stored;
50
51 // TODO: and other member for search.
52
54
55
56//================================================================
65
66
67/***** Global variables *****************************************************/
68/***** Function prototypes **************************************************/
69//@cond
70mrbc_value mrbc_hash_new(mrbc_vm *vm, int size);
72mrbc_value *mrbc_hash_search(const mrbc_value *hash, const mrbc_value *key);
74int mrbc_hash_set(mrbc_value *hash, mrbc_value *key, mrbc_value *val);
75mrbc_value mrbc_hash_get(const mrbc_value *hash, const mrbc_value *key);
76mrbc_value *mrbc_hash_get_p(const mrbc_value *hash, const mrbc_value *key);
79void mrbc_hash_clear(mrbc_value *hash);
80int mrbc_hash_compare(const mrbc_value *v1, const mrbc_value *v2);
82//@endcond
83
84/***** Inline functions *****************************************************/
85//================================================================
88static inline int mrbc_hash_size(const mrbc_value *hash) {
89 return hash->hash->n_stored / 2;
90}
91
92#if defined(MRBC_ALLOC_VMID)
93//================================================================
96static inline void mrbc_hash_clear_vm_id(mrbc_value *hash) {
97 mrbc_array_clear_vm_id(hash);
98}
99#endif
100
101//================================================================
104static inline int mrbc_hash_resize(mrbc_value *hash, int size)
105{
106 return mrbc_array_resize(hash, size * 2);
107}
108
109
110//================================================================
123{
125 ite.target = v->hash;
126 ite.point = v->hash->data;
127 ite.p_end = ite.point + v->hash->n_stored;
128
129 return ite;
130}
131
132//================================================================
136{
137 return ite->point < ite->p_end;
138}
139
140//================================================================
144{
145 mrbc_value *ret = ite->point;
146 ite->point += 2;
147 return ret;
148}
149
150
151#ifdef __cplusplus
152}
153#endif
154#endif
struct RObject mrbc_value
Value object. Default version.
int mrbc_array_resize(mrbc_value *ary, int size)
Definition c_array.c:147
mruby/c Array class
mrbc_value mrbc_hash_get(const mrbc_value *hash, const mrbc_value *key)
Definition c_hash.c:189
mrbc_value * mrbc_hash_search(const mrbc_value *hash, const mrbc_value *key)
Definition c_hash.c:115
mrbc_value mrbc_hash_remove(mrbc_value *hash, const mrbc_value *key)
Definition c_hash.c:217
void mrbc_hash_clear(mrbc_value *hash)
Definition c_hash.c:268
int mrbc_hash_compare(const mrbc_value *v1, const mrbc_value *v2)
Definition c_hash.c:284
mrbc_value mrbc_hash_dup(mrbc_vm *vm, mrbc_value *src)
Definition c_hash.c:305
mrbc_value * mrbc_hash_get_p(const mrbc_value *hash, const mrbc_value *key)
Definition c_hash.c:203
mrbc_value mrbc_hash_remove_by_id(mrbc_value *hash, mrbc_sym sym_id)
Definition c_hash.c:245
mrbc_value mrbc_hash_new(mrbc_vm *vm, int size)
Definition c_hash.c:78
void mrbc_hash_delete(mrbc_value *hash)
Definition c_hash.c:100
mrbc_value * mrbc_hash_search_by_id(const mrbc_value *hash, mrbc_sym sym_id)
Definition c_hash.c:137
int mrbc_hash_set(mrbc_value *hash, mrbc_value *key, mrbc_value *val)
Definition c_hash.c:160
struct RHash mrbc_hash
Hash object.
static mrbc_value * mrbc_hash_i_next(mrbc_hash_iterator *ite)
Definition c_hash.h:143
static int mrbc_hash_size(const mrbc_value *hash)
Definition c_hash.h:88
static int mrbc_hash_i_has_next(mrbc_hash_iterator *ite)
Definition c_hash.h:135
struct RHashIterator mrbc_hash_iterator
Define Hash iterator.
static int mrbc_hash_resize(mrbc_value *hash, int size)
Definition c_hash.h:104
static mrbc_hash_iterator mrbc_hash_iterator_new(const mrbc_value *v)
Definition c_hash.h:122
Hash object.
Definition c_hash.h:42
uint16_t data_size
data buffer size.
Definition c_hash.h:47
uint16_t n_stored
num of stored.
Definition c_hash.h:48
mrbc_value * data
pointer to allocated memory.
Definition c_hash.h:49
MRBC_OBJECT_HEADER
Definition c_hash.h:45
Define Hash iterator.
Definition c_hash.h:60
mrbc_value * p_end
Definition c_hash.h:63
mrbc_hash * target
Definition c_hash.h:61
mrbc_value * point
Definition c_hash.h:62
struct RHash * hash
Definition boxing_no.h:34
mruby/c value definitions
int16_t mrbc_sym
mruby/c symbol ID
Definition value.h:62
mruby bytecode executor.
struct VM mrbc_vm
Virtual Machine.