11#include "ruby/internal/config.h"
17#define RHASH_AR_TABLE_MAX_SIZE SIZEOF_VALUE
20typedef unsigned char ar_hint_t;
22enum ruby_rhash_flags {
27 RHASH_AR_TABLE_SIZE_SHIFT = (
FL_USHIFT+4),
29 RHASH_AR_TABLE_BOUND_SHIFT = (
FL_USHIFT+8),
33#define RHASH_LEV_MASK (FL_USER13 | FL_USER14 | FL_USER15 | \
34 FL_USER16 | FL_USER17 | FL_USER18 | FL_USER19)
47 ar_hint_t ary[RHASH_AR_TABLE_MAX_SIZE];
51 ar_table_pair pairs[RHASH_AR_TABLE_MAX_SIZE];
59#define RHASH(obj) ((struct RHash *)(obj))
77long rb_dbl_long_hash(
double d);
78st_table *rb_init_identtable(
void);
79void rb_init_existing_identtable_with_size(st_table *tbl, st_index_t size);
80st_index_t rb_any_hash(
VALUE a);
88int rb_hash_stlike_delete(
VALUE hash, st_data_t *pkey, st_data_t *pval);
89int rb_hash_stlike_update(
VALUE hash, st_data_t key, st_update_callback_func *func, st_data_t arg);
90bool rb_hash_default_unredefined(
VALUE hash);
93void rb_hash_free(
VALUE hash);
97static inline unsigned RHASH_AR_TABLE_SIZE_RAW(
VALUE h);
101static inline bool RHASH_AR_TABLE_P(
VALUE h);
102static inline bool RHASH_ST_TABLE_P(
VALUE h);
104static inline st_table *RHASH_ST_TABLE(
VALUE h);
105static inline size_t RHASH_ST_SIZE(
VALUE h);
106static inline void RHASH_ST_CLEAR(
VALUE h);
108RUBY_SYMBOL_EXPORT_BEGIN
111VALUE rb_ident_hash_new(
void);
114int rb_hash_stlike_foreach(
VALUE hash, st_foreach_callback_func *func, st_data_t arg);
115int rb_hash_stlike_foreach_with_replace(
VALUE hash, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg);
116RUBY_SYMBOL_EXPORT_END
122int rb_hash_stlike_lookup(
VALUE hash, st_data_t key, st_data_t *pval);
127st_table *rb_hash_tbl_raw(
VALUE hash);
132RHASH_AR_TABLE_P(
VALUE h)
139RHASH_AR_TABLE(
VALUE h)
145static inline st_table *
146RHASH_ST_TABLE(
VALUE h)
148 return (st_table *)((uintptr_t)h +
sizeof(
struct RHash));
154 return RHASH(h)->ifnone;
160 if (RHASH_AR_TABLE_P(h)) {
161 return RHASH_AR_TABLE_SIZE_RAW(h);
164 return RHASH_ST_SIZE(h);
175RHASH_ST_TABLE_P(
VALUE h)
177 return ! RHASH_AR_TABLE_P(h);
181RHASH_ST_SIZE(
VALUE h)
183 return RHASH_ST_TABLE(h)->num_entries;
187RHASH_ST_CLEAR(
VALUE h)
189 memset(RHASH_ST_TABLE(h), 0,
sizeof(st_table));
192static inline unsigned
193RHASH_AR_TABLE_SIZE_RAW(
VALUE h)
196 ret >>= RHASH_AR_TABLE_SIZE_SHIFT;
197 return (
unsigned)ret;
200#define RHASH_AR_TABLE_BOUND_RAW(h) \
201 ((unsigned int)((RBASIC(h)->flags >> RHASH_AR_TABLE_BOUND_SHIFT) & \
202 (RHASH_AR_TABLE_BOUND_MASK >> RHASH_AR_TABLE_BOUND_SHIFT)))
205static inline unsigned int
206RHASH_AR_TABLE_BOUND(
VALUE h)
209 const unsigned int bound = RHASH_AR_TABLE_BOUND_RAW(h);
214#define RHASH_ST_SLOT_SIZE (sizeof(struct RHash) + sizeof(st_table))
217RHASH_AR_SLOT_SIZE(
size_t capa)
219 return sizeof(
struct RHash) + offsetof(ar_table, pairs) +
capa *
sizeof(ar_table_pair);
#define RUBY_EXTERN
Declaration of externally visible global variables.
#define FL_USER3
Old name of RUBY_FL_USER3.
#define FL_USER7
Old name of RUBY_FL_USER7.
#define FL_USER10
Old name of RUBY_FL_USER10.
#define FL_USER6
Old name of RUBY_FL_USER6.
#define FL_USER1
Old name of RUBY_FL_USER1.
#define FL_USER12
Old name of RUBY_FL_USER12.
#define FL_USER11
Old name of RUBY_FL_USER11.
#define FL_USER8
Old name of RUBY_FL_USER8.
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
#define FL_USER2
Old name of RUBY_FL_USER2.
#define FL_USER9
Old name of RUBY_FL_USER9.
#define FL_USER5
Old name of RUBY_FL_USER5.
#define FL_USHIFT
Old name of RUBY_FL_USHIFT.
#define FL_USER4
Old name of RUBY_FL_USER4.
#define RBIMPL_ASSERT_OR_ASSUME(...)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
int capa
Designed capacity of the buffer.
#define RBIMPL_ATTR_RETURNS_NONNULL()
Wraps (or simulates) __attribute__((returns_nonnull)).
#define RHASH_SIZE(h)
Queries the size of the hash.
#define RHASH_EMPTY_P(h)
Checks if the hash is empty.
C99 shim for <stdbool.h>.
Ruby object's base components.
const VALUE klass
Class of an object.
long rb_len_t
A signed integer type for lengths and indices of objects such as String and Array.
uintptr_t VALUE
Type that represents a Ruby object.