Ruby 4.1.0dev (2026-09-30 revision e45f082e39924a0cd0644a1287ae2391df7321d2)
Macros | Functions
rhash.h File Reference

(e45f082e39924a0cd0644a1287ae2391df7321d2)

Routines to manipulate struct RHash. More...

#include "ruby/internal/config.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
#include "ruby/backward.h"
Include dependency graph for rhash.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define RHASH_IFNONE(h)   rb_hash_ifnone(h)
 
#define RHASH_SIZE(h)   rb_hash_size_num(h)
 Queries the size of the hash.
 
#define RHASH_EMPTY_P(h)   (RHASH_SIZE(h) == 0)
 Checks if the hash is empty.
 
#define RHASH_SET_IFNONE(h, ifnone)   rb_hash_set_ifnone((VALUE)h, ifnone)
 Destructively updates the default value of the hash.
 

Functions

size_t rb_hash_size_num (VALUE hash)
 This is the implementation detail of RHASH_SIZE.
 
struct st_table * rb_hash_tbl (VALUE hash)
 This is the implementation detail of RHASH_TBL.
 
static st_table * RHASH_TBL (VALUE h)
 Retrieves the internal table.
 
VALUE rb_hash_set_ifnone (VALUE hash, VALUE ifnone)
 This is the implementation detail of RHASH_SET_IFNONE.
 

Detailed Description

Routines to manipulate struct RHash.

Author
Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org
Warning
Symbols prefixed with either RBIMPL or rbimpl are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.
Note
To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance __VA_ARGS__ is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.
The struct RHash itself is opaque.

Definition in file rhash.h.

Macro Definition Documentation

◆ RHASH_EMPTY_P

#define RHASH_EMPTY_P (   h)    (RHASH_SIZE(h) == 0)

Checks if the hash is empty.

Parameters
[in]hAn instance of RHash.
Precondition
h must be of RUBY_T_HASH.
Return values
trueIt is.
falseIt isn't.

Definition at line 67 of file rhash.h.

◆ RHASH_IFNONE

#define RHASH_IFNONE (   h)    rb_hash_ifnone(h)
Deprecated:
This macro once was a thing in the old days, but makes no sense any longer today. Exists here for backwards compatibility only. You can safely forget about it.

Definition at line 47 of file rhash.h.

◆ RHASH_SET_IFNONE

#define RHASH_SET_IFNONE (   h,
  ifnone 
)    rb_hash_set_ifnone((VALUE)h, ifnone)

Destructively updates the default value of the hash.

Parameters
[out]hAn instance of RHash.
[in]ifnoneArbitrary default value.
Precondition
h must be of RUBY_T_HASH.

Definition at line 80 of file rhash.h.

◆ RHASH_SIZE

#define RHASH_SIZE (   h)    rb_hash_size_num(h)

Queries the size of the hash.

Size here means the number of keys that the hash stores.

Parameters
[in]hAn instance of RHash.
Precondition
h must be of RUBY_T_HASH.
Returns
The size of the hash.

Definition at line 57 of file rhash.h.

Function Documentation

◆ rb_hash_set_ifnone()

VALUE rb_hash_set_ifnone ( VALUE  hash,
VALUE  ifnone 
)

This is the implementation detail of RHASH_SET_IFNONE.

People don't call this directly.

Parameters
[out]hashAn instance of RHash.
[in]ifnoneArbitrary default value.
Precondition
hash must be of RUBY_T_HASH.

Definition at line 133 of file hash.c.

◆ rb_hash_size_num()

size_t rb_hash_size_num ( VALUE  hash)

This is the implementation detail of RHASH_SIZE.

People don't call this directly.

Parameters
[in]hashAn instance of RHash.
Precondition
hash must be of RUBY_T_HASH.
Returns
The size of the hash.

Definition at line 3265 of file hash.c.

◆ rb_hash_tbl()

struct st_table * rb_hash_tbl ( VALUE  hash)

This is the implementation detail of RHASH_TBL.

People don't call this directly.

Parameters
[in]hashAn instance of RHash.
[in]fileThe __FILE__.
[in]lineThe __LINE__.
Precondition
hash must be of RUBY_T_HASH.
Returns
Table that has the contents of the hash.

Definition at line 1804 of file hash.c.

Referenced by RHASH_TBL().

◆ RHASH_TBL()

static st_table * RHASH_TBL ( VALUE  h)
inlinestatic

Retrieves the internal table.

Parameters
[in]hAn instance of RHash.
Precondition
h must be of RUBY_T_HASH.
Returns
A struct st_table which has the contents of this hash.
Note
Nowadays as Ruby evolved over ages, RHash has multiple backend storage engines. h's backend is not guaranteed to be a st_table. This function creates one when necessary.
Deprecated:
This imposes that RHash can backed by a struct st_table which is limiting runtime optimizations.

Definition at line 122 of file rhash.h.