Function: map-length

map-length is a byte-compiled function defined in map.el.gz.

Signature

(map-length MAP)

Documentation

Return the number of key/value pairs in MAP.

Note that this does not always reflect the number of unique keys. The default implementation delegates to map-do.

Other relevant functions are documented in the map group.

Shortdoc

;; map
(map-length (list 'bar 1 'foo 2 'baz 3))
    => 3
  (map-length (list '(bar . 1) '(foo . 2) '(baz . 3)))
    => 3
  (map-length [bar foo baz])
    => 3
  (map-length #s(hash-table data (bar 1 foo 2 baz 3)))
    => 3

Implementations

(map-length (MAP array)) in `map.el'.

Implementation of `map-length' for maps that are arrays. In a map that is an array, the keys are the slot indices, and slot contents are the values. Value is the number of slots in MAP.

(map-length (MAP list)) in `map.el'.

Implementation of `map-length' for maps that are plists or alists. Value is the number of property-value pairs for plists and the number of association cons cells in an alist.

(map-length (MAP hash-table)) in `map.el'.

Implementation of `map-length' for maps that are hash-tables. Value is the number of elements in MAP.

(map-length MAP) in `map.el'.

Undocumented

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/map.el.gz
(cl-defgeneric map-length (map)
  ;; FIXME: Should we rename this to `map-size'?
  "Return the number of key/value pairs in MAP.
Note that this does not always reflect the number of unique keys.
The default implementation delegates to `map-do'."
  (let ((size 0))
    (map-do (lambda (_k _v) (setq size (1+ size))) map)
    size))