Ruby  3.4.0dev (2024-11-05 revision 348a53415339076afc4a02fcd09f3ae36e9c4c61)
Macros | Functions
rhash.h File Reference

(348a53415339076afc4a02fcd09f3ae36e9c4c61)

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_TBL(h)   rb_hash_tbl(h, __FILE__, __LINE__)
 Retrieves the internal table. More...
 
#define RHASH_IFNONE(h)   rb_hash_ifnone(h)
 
#define RHASH_SIZE(h)   rb_hash_size_num(h)
 Queries the size of the hash. More...
 
#define RHASH_EMPTY_P(h)   (RHASH_SIZE(h) == 0)
 Checks if the hash is empty. More...
 
#define RHASH_SET_IFNONE(h, ifnone)   rb_hash_set_ifnone((VALUE)h, ifnone)
 Destructively updates the default value of the hash. More...
 

Functions

size_t rb_hash_size_num (VALUE hash)
 This is the implementation detail of RHASH_SIZE. More...
 
struct st_tablerb_hash_tbl (VALUE hash, const char *file, int line)
 This is the implementation detail of RHASH_TBL. More...
 
VALUE rb_hash_set_ifnone (VALUE hash, VALUE ifnone)
 This is the implementation detail of RHASH_SET_IFNONE. More...
 

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 79 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 59 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 92 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 69 of file rhash.h.

◆ 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 123 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 2960 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 1593 of file hash.c.