Function: -same-items?

-same-items? is a byte-compiled function defined in dash.el.

Signature

(-same-items? LIST1 LIST2)

Documentation

Return non-nil if LIST1 and LIST2 have the same distinct elements.

The order of the elements in the lists does not matter. The lists may be of different lengths, i.e., contain duplicate elements. The test for equality is done with equal, or with
-compare-fn if that is non-nil.

Alias: -same-items-p.

View in manual

Aliases

-same-items-p

Source Code

;; Defined in ~/.emacs.d/elpa/dash-20260221.1346/dash.el
(defun -same-items? (list1 list2)
  "Return non-nil if LIST1 and LIST2 have the same distinct elements.

The order of the elements in the lists does not matter.  The
lists may be of different lengths, i.e., contain duplicate
elements.  The test for equality is done with `equal', or with
`-compare-fn' if that is non-nil.

Alias: `-same-items-p'."
  (declare (important-return-value t))
  (let (test len1 len2)
    (cond ((null (or list1 list2)))
          ((null (and list1 list2)) nil)
          ;; Use a hash table if `-compare-fn' is a known hash table
          ;; test function and either list is long enough.
          ((and (setq test (dash--hash-test-fn))
                (setq len1 (length list1))
                (setq len2 (length list2))
                (> (max len1 len2) dash--short-list-length))
           (let ((ht1 (make-hash-table :test test :size len1))
                 (ht2 (make-hash-table :test test :size len2)))
             (--each list1 (puthash it t ht1))
             ;; Move visited elements from `ht1' to `ht2'.  This way,
             ;; if visiting all of `list2' leaves `ht1' empty, then
             ;; all elements from both lists have been accounted for.
             (and (--every (cond ((gethash it ht1)
                                  (remhash it ht1)
                                  (puthash it t ht2))
                                 ((gethash it ht2)))
                           list2)
                  (zerop (hash-table-count ht1)))))
          ((let ((member (dash--member-fn)))
             (and (--all? (funcall member it list2) list1)
                  (--all? (funcall member it list1) list2)))))))