Ruby 3.2.3p157 (2024-01-18 revision 52bb2ac0a6971d0391efa2275f7a66bff319087c)
Macros | Functions
rhash.h File Reference

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"

Go to the source code of this file.

Macros

#define RHASH_TBL(h)   rb_hash_tbl(h, __FILE__, __LINE__)
 Retrieves the internal table.
 
#define RHASH_ITER_LEV(h)   rb_hash_iter_lev(h)
 
#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_tablerb_hash_tbl (VALUE hash, const char *file, int line)
 This is the implementation detail of RHASH_TBL.
 
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 92 of file rhash.h.

Referenced by rb_extract_keywords().

◆ 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 72 of file rhash.h.

◆ RHASH_ITER_LEV

#define RHASH_ITER_LEV ( h)    rb_hash_iter_lev(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 59 of file rhash.h.

Referenced by rb_hash_aset(), and rb_hash_clear().

◆ 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 105 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 82 of file rhash.h.

Referenced by rb_get_kwargs(), rb_hash_size(), and rb_hash_size_num().

◆ RHASH_TBL

#define RHASH_TBL ( h)    rb_hash_tbl(h, __FILE__, __LINE__)

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.

Definition at line 46 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 103 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 3026 of file hash.c.

◆ rb_hash_tbl()

struct st_table * rb_hash_tbl ( VALUE hash,
const char * file,
int line )

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 1641 of file hash.c.