Function: puthash

puthash is a function defined in fns.c.

Signature

(puthash KEY VALUE TABLE)

Documentation

Associate KEY with VALUE in hash table TABLE.

If KEY is already present in table, replace its current value with VALUE. In any case, return VALUE.

Other relevant functions are documented in the hash-table group.

View in manual

Probably introduced at or before Emacs version 21.1.

Shortdoc

;; hash-table
(puthash 'key "value" table)

Aliases

cl-puthash (obsolete since 24.3)

Source Code

// Defined in /usr/src/emacs/src/fns.c
{
  struct Lisp_Hash_Table *h = check_hash_table (table);
  check_mutable_hash_table (table, h);

  EMACS_UINT hash = hash_from_key (h, key);
  ptrdiff_t i = hash_lookup_with_hash (h, key, hash);
  if (i >= 0)
    set_hash_value_slot (h, i, value);
  else
    hash_put (h, key, value, hash);

  return value;
}