Ruby: internal/hash.h File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Data Structures | Macros | Typedefs | Enumerations | Functions
hash.h File Reference

Internal header for Hash. More...

`#include "ruby/internal/config.h"`
`#include <stddef.h>`
`#include "ruby/internal/stdbool.h"`
`#include "ruby/ruby.h"`
`#include "ruby/st.h"`

Go to the source code of this file.

## Data Structures
struct | RHash

## Macros
#define | RHASH_AR_TABLE_MAX_SIZE SIZEOF_VALUE
#define | RHASH_LEV_MASK
#define | RHASH(obj) ((struct RHash *)(obj))
#define | RHASH_TBL_RAW(h) rb_hash_tbl_raw(h, __FILE__, __LINE__)

## Typedefs
typedef unsigned char | ar_hint_t

## Enumerations
enum | ruby_rhash_flags { RHASH_PASS_AS_KEYWORDS = FL_USER1 , RHASH_PROC_DEFAULT = FL_USER2 , RHASH_ST_TABLE_FLAG = FL_USER3 , RHASH_AR_TABLE_SIZE_MASK = (FL_USER4|FL_USER5|FL_USER6|FL_USER7) , RHASH_AR_TABLE_SIZE_SHIFT = (FL_USHIFT+4) , RHASH_AR_TABLE_BOUND_MASK = (FL_USER8|FL_USER9|FL_USER10|FL_USER11) , RHASH_AR_TABLE_BOUND_SHIFT = (FL_USHIFT+8) , RHASH_LEV_SHIFT = (FL_USHIFT + 13) , RHASH_LEV_MAX = 127 }

## Functions
void | rb_hash_st_table_set (VALUE hash, st_table *st)
VALUE | rb_hash_default_value (VALUE hash, VALUE key)
VALUE | rb_hash_set_default_proc (VALUE hash, VALUE proc)
long | rb_dbl_long_hash (double d)
st_table * | rb_init_identtable (void)
VALUE | rb_to_hash_type (VALUE obj)
VALUE | rb_hash_key_str (VALUE)
VALUE | rb_hash_values (VALUE hash)
VALUE | rb_hash_rehash (VALUE hash)
int | rb_hash_add_new_element (VALUE hash, VALUE key, VALUE val)
VALUE | rb_hash_set_pair (VALUE hash, VALUE pair)
int | rb_hash_stlike_delete (VALUE hash, st_data_t *pkey, st_data_t *pval)
int | rb_hash_stlike_foreach_with_replace (VALUE hash, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg)
int | rb_hash_stlike_update (VALUE hash, st_data_t key, st_update_callback_func *func, st_data_t arg)
st_table * | rb_hash_st_table (VALUE hash)
VALUE | rb_hash_delete_entry (VALUE hash, VALUE key)
VALUE | rb_ident_hash_new (void)
int | rb_hash_stlike_foreach (VALUE hash, st_foreach_callback_func *func, st_data_t arg)
VALUE | rb_hash_new_with_size (st_index_t size)
VALUE | rb_hash_resurrect (VALUE hash)
int | rb_hash_stlike_lookup (VALUE hash, st_data_t key, st_data_t *pval)
VALUE | rb_hash_keys (VALUE hash)
VALUE | rb_hash_has_key (VALUE hash, VALUE key)
VALUE | rb_hash_compare_by_id_p (VALUE hash)
st_table * | rb_hash_tbl_raw (VALUE hash, const char *file, int line)

## Detailed Description

Internal header for Hash.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Definition in file hash.h.

## Macro Definition Documentation

## ◆ RHASH

#define RHASH | ( |  | obj | ) | ((struct RHash *)(obj))

Definition at line 57 of file hash.h.

## ◆ RHASH_AR_TABLE_MAX_SIZE

#define RHASH_AR_TABLE_MAX_SIZE SIZEOF_VALUE

Definition at line 18 of file hash.h.

## ◆ RHASH_LEV_MASK

#define RHASH_LEV_MASK

Value:
(FL_USER13 | FL_USER14 | FL_USER15 | /* FL 13..19 */ \
FL_USER16 | FL_USER17 | FL_USER18 | FL_USER19)
FL_USER19
#define FL_USER19
Definition: fl_type.h:82
FL_USER15
#define FL_USER15
Definition: fl_type.h:78
FL_USER14
#define FL_USER14
Definition: fl_type.h:77
FL_USER17
#define FL_USER17
Definition: fl_type.h:80
FL_USER18
#define FL_USER18
Definition: fl_type.h:81
FL_USER13
#define FL_USER13
Definition: fl_type.h:76
FL_USER16
#define FL_USER16
Definition: fl_type.h:79

Definition at line 37 of file hash.h.

## ◆ RHASH_TBL_RAW

#define RHASH_TBL_RAW | ( |  | h | ) | rb_hash_tbl_raw(h, __FILE__, __LINE__)

Definition at line 118 of file hash.h.

## Typedef Documentation

## ◆ ar_hint_t

typedef unsigned char ar_hint_t

Definition at line 21 of file hash.h.

## Enumeration Type Documentation

## ◆ ruby_rhash_flags

enum ruby_rhash_flags

Enumerator
RHASH_PASS_AS_KEYWORDS |
RHASH_PROC_DEFAULT |
RHASH_ST_TABLE_FLAG |
RHASH_AR_TABLE_SIZE_MASK |
RHASH_AR_TABLE_SIZE_SHIFT |
RHASH_AR_TABLE_BOUND_MASK |
RHASH_AR_TABLE_BOUND_SHIFT |
RHASH_LEV_SHIFT |
RHASH_LEV_MAX |

Definition at line 23 of file hash.h.

## Function Documentation

## ◆ rb_dbl_long_hash()

long rb_dbl_long_hash | ( | double | d | ) |

Definition at line 180 of file hash.c.

References rb_memhash().

## ◆ rb_hash_add_new_element()

int rb_hash_add_new_element | ( | VALUE | hash,
|  | VALUE | key,
|  | VALUE | val
| ) |  |

Definition at line 4734 of file hash.c.

References st_hash_type::hash, key, RHASH_TBL_RAW, and st_update.

## ◆ rb_hash_compare_by_id_p()

VALUE rb_hash_compare_by_id_p | ( | VALUE | hash | ) |

Definition at line 4432 of file hash.c.

References st_hash_type::hash, identhash, Qfalse, and Qtrue.

Referenced by Init_Hash().

## ◆ rb_hash_default_value()

VALUE rb_hash_default_value | ( | VALUE | hash,
|  | VALUE | key
| ) |  |

Definition at line 1999 of file hash.c.

References CLASS_OF, FL_TEST, key, LIKELY, Qnil, Qundef, rb_funcall(), rb_method_basic_definition_p, RHASH_IFNONE, and RHASH_PROC_DEFAULT.

Referenced by rb_hash_aref(), and rb_str_format().

## ◆ rb_hash_delete_entry()

VALUE rb_hash_delete_entry | ( | VALUE | hash,
|  | VALUE | key
| ) |  |

Definition at line 2309 of file hash.c.

References key, Qundef, and rb_hash_stlike_delete().

Referenced by rb_gc_free_dsymbol(), rb_hash_delete(), and rb_sym2id().

## ◆ rb_hash_has_key()

VALUE rb_hash_has_key | ( | VALUE | hash,
|  | VALUE | key
| ) |  |

Definition at line 3638 of file hash.c.

References key, NULL, Qfalse, and Qtrue.

Referenced by Init_Hash().

## ◆ rb_hash_key_str()

VALUE rb_hash_key_str | ( | VALUE | key | ) |

Definition at line 2852 of file hash.c.

References FL_EXIVAR, key, rb_cString, rb_fstring(), rb_str_new_frozen(), and RBASIC_CLASS.

## ◆ rb_hash_keys()

VALUE rb_hash_keys | ( | VALUE | hash | ) |

Definition at line 3549 of file hash.c.

References ptr, RARRAY_PTR_USE_TRANSIENT, rb_ary_new_capa(), rb_ary_set_len(), rb_gc_writebarrier_remember(), rb_hash_foreach(), RHASH_SIZE, ST_DATA_COMPATIBLE_P, and st_keys.

Referenced by Init_Hash().

## ◆ rb_hash_new_with_size()

VALUE rb_hash_new_with_size | ( | st_index_t | size | ) |

Definition at line 1544 of file hash.c.

References rb_hash_new(), RHASH_AR_TABLE_MAX_SIZE, RHASH_ST_TABLE_SET, and st_init_table_with_size.

Referenced by InitVM_Enumerator().

## ◆ rb_hash_rehash()

VALUE rb_hash_rehash | ( | VALUE | hash | ) |

Definition at line 1960 of file hash.c.

References hash_verify, st_table::num_entries, rb_eRuntimeError, rb_hash_foreach(), rb_raise(), RHASH_ITER_LEV, RHASH_ST_TABLE_SET, st_free_table, st_init_table_with_size, and st_table::type.

Referenced by Init_Hash().

## ◆ rb_hash_resurrect()

VALUE rb_hash_resurrect | ( | VALUE | hash | ) |

Definition at line 1590 of file hash.c.

References hash_foreach_arg::hash, and rb_cHash.

## ◆ rb_hash_set_default_proc()

VALUE rb_hash_set_default_proc | ( | VALUE | hash,
|  | VALUE | proc
| ) |  |

Definition at line 2234 of file hash.c.

References NIL_P, rb_check_convert_type_with_id(), rb_eTypeError, rb_obj_classname(), rb_obj_is_proc(), rb_raise(), SET_DEFAULT, SET_PROC_DEFAULT, and T_DATA.

Referenced by Init_Hash().

## ◆ rb_hash_set_pair()

VALUE rb_hash_set_pair | ( | VALUE | hash,
|  | VALUE | pair
| ) |  |

Definition at line 3468 of file hash.c.

References NIL_P, RARRAY_AREF, RARRAY_LEN, rb_builtin_class_name(), rb_check_array_type(), rb_eArgError, rb_eTypeError, rb_hash_aset(), and rb_raise().

## ◆ rb_hash_st_table()

st_table * rb_hash_st_table | ( | VALUE | hash | ) |

Definition at line 567 of file hash.c.

References HASH_ASSERT, and RHASH.

## ◆ rb_hash_st_table_set()

void rb_hash_st_table_set | ( | VALUE | hash,
|  | st_table * | st
| ) |  |

Definition at line 574 of file hash.c.

References FL_SET_RAW, HASH_ASSERT, NULL, RHASH, and RHASH_ST_TABLE_FLAG.

## ◆ rb_hash_stlike_delete()

int rb_hash_stlike_delete | ( | VALUE | hash,
|  | st_data_t * | pkey,
|  | st_data_t * | pval
| ) |  |

Definition at line 2293 of file hash.c.

References st_delete.

Referenced by rb_hash_delete_entry().

## ◆ rb_hash_stlike_foreach()

int rb_hash_stlike_foreach | ( | VALUE | hash,
|  | st_foreach_callback_func * | func,
|  | st_data_t | arg
| ) |  |

Definition at line 1457 of file hash.c.

References hash_foreach_arg::arg, hash_foreach_arg::func, hash_foreach_arg::hash, and st_foreach.

Referenced by rb_execarg_extract_options().

## ◆ rb_hash_stlike_foreach_with_replace()

int rb_hash_stlike_foreach_with_replace | ( | VALUE | hash,
|  | st_foreach_check_callback_func * | func,
|  | st_update_callback_func * | replace,
|  | st_data_t | arg
| ) |  |

Definition at line 1468 of file hash.c.

References hash_foreach_arg::arg, hash_foreach_arg::func, hash_foreach_arg::hash, and st_foreach_with_replace.

## ◆ rb_hash_stlike_lookup()

int rb_hash_stlike_lookup | ( | VALUE | hash,
|  | st_data_t | key,
|  | st_data_t * | pval
| ) |  |

Definition at line 2026 of file hash.c.

References key.

Referenced by mjit_valid_class_serial_p().

## ◆ rb_hash_stlike_update()

int rb_hash_stlike_update | ( | VALUE | hash,
|  | st_data_t | key,
|  | st_update_callback_func * | func,
|  | st_data_t | arg
| ) |  |

Definition at line 1659 of file hash.c.

References key, and st_update.

## ◆ rb_hash_tbl_raw()

st_table * rb_hash_tbl_raw | ( | VALUE | hash,
|  | const char * | file,
|  | int | line
| ) |  |

Definition at line 1603 of file hash.c.

Referenced by rb_hash_tbl().

## ◆ rb_hash_values()

VALUE rb_hash_values | ( | VALUE | hash | ) |

Definition at line 3593 of file hash.c.

References ptr, RARRAY_PTR_USE_TRANSIENT, rb_ary_new_capa(), rb_ary_set_len(), rb_gc_writebarrier_remember(), rb_hash_foreach(), RHASH_SIZE, ST_DATA_COMPATIBLE_P, and st_values.

Referenced by Init_Hash().

## ◆ rb_init_identtable()

st_table * rb_init_identtable | ( | void |  | ) |

Definition at line 4451 of file hash.c.

References identhash, and st_init_table.

Referenced by Init_MemoryView().

## ◆ rb_to_hash_type()

VALUE rb_to_hash_type | ( | VALUE | obj | ) |

Definition at line 1853 of file hash.c.

References update_arg::hash, rb_convert_type_with_id(), and T_HASH.