mruby/c VM Source Code release 3.4
Loading...
Searching...
No Matches
c_hash.h
Go to the documentation of this file.
1
13
14#ifndef MRBC_SRC_C_HASH_H_
15#define MRBC_SRC_C_HASH_H_
16
17/***** Feature test switches ************************************************/
18/***** System headers *******************************************************/
19//@cond
20#include <stdint.h>
21//@endcond
22
23/***** Local headers ********************************************************/
24#include "value.h"
25#include "c_array.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/***** Constat values *******************************************************/
32/***** Macros ***************************************************************/
33/***** Typedefs *************************************************************/
34//================================================================
40typedef struct RHash {
41 // (NOTE)
42 // Needs to be same members and order as RArray.
44
45 uint16_t data_size;
46 uint16_t n_stored;
48
49 // TODO: and other member for search.
50
52
53
54//================================================================
63
64
65/***** Global variables *****************************************************/
66/***** Function prototypes **************************************************/
67//@cond
68mrbc_value mrbc_hash_new(struct VM *vm, int size);
70mrbc_value *mrbc_hash_search(const mrbc_value *hash, const mrbc_value *key);
72int mrbc_hash_set(mrbc_value *hash, mrbc_value *key, mrbc_value *val);
73mrbc_value mrbc_hash_get(const mrbc_value *hash, const mrbc_value *key);
74mrbc_value *mrbc_hash_get_p(const mrbc_value *hash, const mrbc_value *key);
77void mrbc_hash_clear(mrbc_value *hash);
78int mrbc_hash_compare(const mrbc_value *v1, const mrbc_value *v2);
79mrbc_value mrbc_hash_dup(struct VM *vm, mrbc_value *src);
80//@endcond
81
82/***** Inline functions *****************************************************/
83//================================================================
86static inline int mrbc_hash_size(const mrbc_value *hash) {
87 return hash->hash->n_stored / 2;
88}
89
90#if defined(MRBC_ALLOC_VMID)
91//================================================================
94static inline void mrbc_hash_clear_vm_id(mrbc_value *hash) {
95 mrbc_array_clear_vm_id(hash);
96}
97#endif
98
99//================================================================
102static inline int mrbc_hash_resize(mrbc_value *hash, int size)
103{
104 return mrbc_array_resize(hash, size * 2);
105}
106
107
108//================================================================
121{
123 ite.target = v->hash;
124 ite.point = v->hash->data;
125 ite.p_end = ite.point + v->hash->n_stored;
126
127 return ite;
128}
129
130//================================================================
134{
135 return ite->point < ite->p_end;
136}
137
138//================================================================
142{
143 mrbc_value *ret = ite->point;
144 ite->point += 2;
145 return ret;
146}
147
148
149#ifdef __cplusplus
150}
151#endif
152#endif
int mrbc_array_resize(mrbc_value *ary, int size)
Definition c_array.c:155
mruby/c Array class
mrbc_value mrbc_hash_get(const mrbc_value *hash, const mrbc_value *key)
Definition c_hash.c:197
mrbc_value * mrbc_hash_search(const mrbc_value *hash, const mrbc_value *key)
Definition c_hash.c:123
mrbc_value mrbc_hash_remove(mrbc_value *hash, const mrbc_value *key)
Definition c_hash.c:225
void mrbc_hash_clear(mrbc_value *hash)
Definition c_hash.c:276
int mrbc_hash_compare(const mrbc_value *v1, const mrbc_value *v2)
Definition c_hash.c:292
mrbc_value * mrbc_hash_get_p(const mrbc_value *hash, const mrbc_value *key)
Definition c_hash.c:211
mrbc_value mrbc_hash_remove_by_id(mrbc_value *hash, mrbc_sym sym_id)
Definition c_hash.c:253
void mrbc_hash_delete(mrbc_value *hash)
Definition c_hash.c:108
mrbc_value * mrbc_hash_search_by_id(const mrbc_value *hash, mrbc_sym sym_id)
Definition c_hash.c:145
mrbc_value mrbc_hash_dup(struct VM *vm, mrbc_value *src)
Definition c_hash.c:313
int mrbc_hash_set(mrbc_value *hash, mrbc_value *key, mrbc_value *val)
Definition c_hash.c:168
mrbc_value mrbc_hash_new(struct VM *vm, int size)
Definition c_hash.c:77
struct RHash mrbc_hash
Hash object.
static mrbc_value * mrbc_hash_i_next(mrbc_hash_iterator *ite)
Definition c_hash.h:141
static int mrbc_hash_size(const mrbc_value *hash)
Definition c_hash.h:86
static int mrbc_hash_i_has_next(mrbc_hash_iterator *ite)
Definition c_hash.h:133
struct RHashIterator mrbc_hash_iterator
Define Hash iterator.
static int mrbc_hash_resize(mrbc_value *hash, int size)
Definition c_hash.h:102
static mrbc_hash_iterator mrbc_hash_iterator_new(const mrbc_value *v)
Definition c_hash.h:120
Hash object.
Definition c_hash.h:40
uint16_t data_size
data buffer size.
Definition c_hash.h:45
uint16_t n_stored
num of stored.
Definition c_hash.h:46
mrbc_value * data
pointer to allocated memory.
Definition c_hash.h:47
MRBC_OBJECT_HEADER
Definition c_hash.h:43
Define Hash iterator.
Definition c_hash.h:58
mrbc_value * p_end
Definition c_hash.h:61
mrbc_hash * target
Definition c_hash.h:59
mrbc_value * point
Definition c_hash.h:60
struct RHash * hash
Definition value.h:166
Virtual Machine.
Definition vm.h:140
mruby/c value definitions
int16_t mrbc_sym
mruby/c symbol ID
Definition value.h:59
struct RObject mrbc_value
Definition value.h:174