Header: mruby/hash.h

Overview

Hash class

Function Summary collapse

Define Summary

#define MRUBY_HASH_H
#define mrb_hash_ptr
#define mrb_hash_value
#define RHASH

RHASH_TBL allocates st_table if not available.

#define RHASH_TBL
#define RHASH_IFNONE
#define RHASH_PROCDEFAULT
#define MRB_HASH_DEFAULT
#define MRB_HASH_PROC_DEFAULT
#define MRB_RHASH_DEFAULT_P
#define MRB_RHASH_PROCDEFAULT_P

Function Details

mrb_value mrb_hash_new_capa(mrb_state * mrb, mrb_int capa)

mrb_value mrb_ensure_hash_type(mrb_state * mrb, mrb_value hash)

mrb_value mrb_check_hash_type(mrb_state * mrb, mrb_value hash)

mrb_value mrb_hash_new(mrb_state * mrb)

Initializes a new hash.

Equivalent to:

 Hash.new

Parameters:

  • mrb

    The mruby state reference.

Returns:

  • The initialized hash.

void mrb_hash_set(mrb_state * mrb, mrb_value hash, mrb_value key, mrb_value val)

Sets a keys and values to hashes.

Equivalent to:

 hash[key] = val

Parameters:

  • mrb

    The mruby state reference.

  • hash

    The target hash.

  • key

    The key to set.

  • val

    The value to set.

Returns:

  • The value.

mrb_value mrb_hash_get(mrb_state * mrb, mrb_value hash, mrb_value key)

Gets a value from a key. If the key is not found, the default of the hash is used.

Equivalent to:

hash[key]

Parameters:

  • mrb

    The mruby state reference.

  • hash

    The target hash.

  • key

    The key to get.

Returns:

  • The found value.

mrb_value mrb_hash_fetch(mrb_state * mrb, mrb_value hash, mrb_value key, mrb_value def)

Gets a value from a key. If the key is not found, the default parameter is used.

Equivalent to:

hash.key?(key) ? hash[key] : def

Parameters:

  • mrb

    The mruby state reference.

  • hash

    The target hash.

  • key

    The key to get.

  • def

    The default value.

Returns:

  • The found value.

mrb_value mrb_hash_delete_key(mrb_state * mrb, mrb_value hash, mrb_value key)

Deletes hash key and value pair.

Equivalent to:

hash.delete(key)

Parameters:

  • mrb

    The mruby state reference.

  • hash

    The target hash.

  • key

    The key to delete.

Returns:

  • The deleted value. This value is not protected from GC. Use mrb_gc_protect() if necessary.

mrb_value mrb_hash_keys(mrb_state * mrb, mrb_value hash)

Gets an array of keys.

Equivalent to:

hash.keys

Parameters:

  • mrb

    The mruby state reference.

  • hash

    The target hash.

Returns:

  • An array with the keys of the hash.

mrb_bool mrb_hash_key_p(mrb_state * mrb, mrb_value hash, mrb_value key)

Check if the hash has the key.

Equivalent to:

hash.key?(key)

Parameters:

  • mrb

    The mruby state reference.

  • hash

    The target hash.

  • key

    The key to check existence.

Returns:

  • True if the hash has the key

mrb_bool mrb_hash_empty_p(mrb_state * mrb, mrb_value self)

Check if the hash is empty

Equivalent to:

hash.empty?

Parameters:

  • mrb

    The mruby state reference.

  • self

    The target hash.

Returns:

  • True if the hash is empty, false otherwise.

mrb_value mrb_hash_values(mrb_state * mrb, mrb_value hash)

Gets an array of values.

Equivalent to:

hash.values

Parameters:

  • mrb

    The mruby state reference.

  • hash

    The target hash.

Returns:

  • An array with the values of the hash.

mrb_value mrb_hash_clear(mrb_state * mrb, mrb_value hash)

Clears the hash.

Equivalent to:

hash.clear

Parameters:

  • mrb

    The mruby state reference.

  • hash

    The target hash.

Returns:

  • The hash

mrb_int mrb_hash_size(mrb_state * mrb, mrb_value hash)

Get hash size.

Equivalent to:

 hash.size

Parameters:

  • mrb

    The mruby state reference.

  • hash

    The target hash.

Returns:

  • The hash size.

mrb_value mrb_hash_dup(mrb_state * mrb, mrb_value hash)

Copies the hash.

Parameters:

  • mrb

    The mruby state reference.

  • hash

    The target hash.

Returns:

  • The copy of the hash

void mrb_hash_merge(mrb_state * mrb, mrb_value hash1, mrb_value hash2)

Merges two hashes. The first hash will be modified by the second hash.

Parameters:

  • mrb

    The mruby state reference.

  • hash1

    The target hash.

  • hash2

    Updating hash

void mrb_hash_foreach(mrb_state * mrb, struct RHash * hash, mrb_hash_foreach_func * func, void * p)