From 02679117fffb490b75758921d3716a88d8bf5c0a Mon Sep 17 00:00:00 2001 From: "waldemar%netscape.com" Date: Thu, 1 Feb 2001 03:41:18 +0000 Subject: [PATCH] Added hash-table-= git-svn-id: svn://10.0.0.236/trunk@85931 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/semantics/Utilities.lisp | 13 +++++++++++++ mozilla/js2/semantics/Utilities.lisp | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/mozilla/js/semantics/Utilities.lisp b/mozilla/js/semantics/Utilities.lisp index b2871c101ba..56c84bd53cb 100644 --- a/mozilla/js/semantics/Utilities.lisp +++ b/mozilla/js/semantics/Utilities.lisp @@ -336,6 +336,19 @@ entries)) +; Return true if the two hash tables are equal, using the given equality test for testing their elements. +(defun hash-table-= (hash-table1 hash-table2 &key (test #'eql)) + (and (= (hash-table-count hash-table1) (hash-table-count hash-table2)) + (progn + (maphash + #'(lambda (key1 value1) + (multiple-value-bind (value2 present2) (gethash key1 hash-table2) + (unless (and present2 (funcall test value1 value2)) + (return-from hash-table-= nil)))) + hash-table1) + t))) + + ; Given an association list ((key1 . data1) (key2 . data2) ... (keyn datan)), ; produce another association list whose keys are sets of the keys of the original list, ; where the data elements of each such set are equal according to the given test function. diff --git a/mozilla/js2/semantics/Utilities.lisp b/mozilla/js2/semantics/Utilities.lisp index b2871c101ba..56c84bd53cb 100644 --- a/mozilla/js2/semantics/Utilities.lisp +++ b/mozilla/js2/semantics/Utilities.lisp @@ -336,6 +336,19 @@ entries)) +; Return true if the two hash tables are equal, using the given equality test for testing their elements. +(defun hash-table-= (hash-table1 hash-table2 &key (test #'eql)) + (and (= (hash-table-count hash-table1) (hash-table-count hash-table2)) + (progn + (maphash + #'(lambda (key1 value1) + (multiple-value-bind (value2 present2) (gethash key1 hash-table2) + (unless (and present2 (funcall test value1 value2)) + (return-from hash-table-= nil)))) + hash-table1) + t))) + + ; Given an association list ((key1 . data1) (key2 . data2) ... (keyn datan)), ; produce another association list whose keys are sets of the keys of the original list, ; where the data elements of each such set are equal according to the given test function.