(defun hash-table-get-all-keys (hash-table) (let ((keys ()) ) (maphash (lambda (k v) (push k keys)) hash-table) keys)) (defun dojo-common-containers-get-hashtable-size (hash-table) (if (null hash-table) 0 (let ((size 0)) (maphash (lambda (key value) (incf size)) hash-table) size))) (defun dojo-common-containers-binary-search (seq value comparator-fct &optional accessor-fct) "Given a sequence sorted in ascending order, this function returns the index of the first element that is greater or equal than the given element, in terms of the given comparator function like string<. The elements of the sequence can either have the data type of the comparator function parameters, or something else. In the latter case, an accessor-fct must be given which derives the values to be used for the compare from the sequence elements." (let* ((first-index 0) (last-index (length seq))) (while (> (- last-index first-index) 1) (let* ((middle-index (+ first-index (/ (- last-index first-index) 2))) (middle-element (seq-elt seq middle-index)) (middle-value (if accessor-fct (funcall accessor-fct middle-element) middle-element))) (if (funcall comparator-fct value middle-value) (setq last-index middle-index) (setq first-index middle-index)))) (let* ((first-element (seq-elt seq first-index)) (first-value (if accessor-fct (funcall accessor-fct first-element) first-element)) (last-element (seq-elt seq last-index)) (last-value (if accessor-fct (funcall accessor-fct last-element) last-element))) (if (funcall comparator-fct first-value value) last-index first-index)))) (provide 'dojo-common-containers)