Function: hash-make-prepend

hash-make-prepend is a byte-compiled function defined in hasht.el.

Signature

(hash-make-prepend INITIALIZER &optional REVERSE)

Documentation

Create and return a hash table from INITIALIZER.

INITIALIZER may be an alist with elements of the form (<value> . <key>) from which the hash table is built (<key> must be a string). Optional non-nil second argument REVERSE means INITIALIZER has elements of form
(<key> . <value>).

The resultant value associated with a <key> is a list of all of the <values> given in INITIALIZER entries which contain the <key>. The values are listed in reverse order of occurrence (they are prepended to the list). See hash-make to use only the last value associated with a given <key>.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hasht.el
(defun hash-make-prepend (initializer &optional reverse)
  "Create and return a hash table from INITIALIZER.
INITIALIZER may be an alist with elements of the form (<value> . <key>) from
which the hash table is built (<key> must be a string).  Optional
non-nil second argument REVERSE means INITIALIZER has elements of form
\(<key> . <value>).

The resultant value associated with a <key> is a list of all of the <values>
given in INITIALIZER entries which contain the <key>.  The values are listed
in reverse order of occurrence (they are prepended to the list).  See
`hash-make' to use only the last value associated with a given <key>."
  (let* ((hash-table (make-hash-table :size (length initializer)))
	 key value key-sym)
    (mapc
     (lambda (cns)
       (when (consp cns)
	 (if reverse
	     (setq key (car cns) value (cdr cns))
	   (setq key (cdr cns) value (car cns))))
       (when (setq key-sym (intern key))
	 (puthash key-sym (cons value (gethash key-sym hash-table)) hash-table)))
     initializer)
    hash-table))