From 06347ce8256b3da77276c7efe5eb9c6ec1bb398d Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Tue, 13 Nov 2018 14:58:43 +0100 Subject: [PATCH] update ht. Signed-off-by: Andreas Gerler --- elpa/ht-20140122.1555/ht-autoloads.el | 18 --- elpa/ht-20140122.1555/ht-pkg.el | 1 - elpa/ht-20180129.2234/ht-autoloads.el | 22 ++++ elpa/ht-20180129.2234/ht-pkg.el | 2 + .../ht.el | 121 ++++++++++-------- 5 files changed, 92 insertions(+), 72 deletions(-) delete mode 100644 elpa/ht-20140122.1555/ht-autoloads.el delete mode 100644 elpa/ht-20140122.1555/ht-pkg.el create mode 100644 elpa/ht-20180129.2234/ht-autoloads.el create mode 100644 elpa/ht-20180129.2234/ht-pkg.el rename elpa/{ht-20140122.1555 => ht-20180129.2234}/ht.el (73%) diff --git a/elpa/ht-20140122.1555/ht-autoloads.el b/elpa/ht-20140122.1555/ht-autoloads.el deleted file mode 100644 index 0a7f388a..00000000 --- a/elpa/ht-20140122.1555/ht-autoloads.el +++ /dev/null @@ -1,18 +0,0 @@ -;;; ht-autoloads.el --- automatically extracted autoloads -;; -;;; Code: - - -;;;### (autoloads nil nil ("ht-pkg.el" "ht.el") (21490 25514 19539 -;;;;;; 0)) - -;;;*** - -(provide 'ht-autoloads) -;; Local Variables: -;; version-control: never -;; no-byte-compile: t -;; no-update-autoloads: t -;; coding: utf-8 -;; End: -;;; ht-autoloads.el ends here diff --git a/elpa/ht-20140122.1555/ht-pkg.el b/elpa/ht-20140122.1555/ht-pkg.el deleted file mode 100644 index a83f4b92..00000000 --- a/elpa/ht-20140122.1555/ht-pkg.el +++ /dev/null @@ -1 +0,0 @@ -(define-package "ht" "20140122.1555" "The missing hash table library for Emacs" (quote nil)) diff --git a/elpa/ht-20180129.2234/ht-autoloads.el b/elpa/ht-20180129.2234/ht-autoloads.el new file mode 100644 index 00000000..c860d466 --- /dev/null +++ b/elpa/ht-20180129.2234/ht-autoloads.el @@ -0,0 +1,22 @@ +;;; ht-autoloads.el --- automatically extracted autoloads +;; +;;; Code: + +(add-to-list 'load-path (directory-file-name + (or (file-name-directory #$) (car load-path)))) + + +;;;### (autoloads nil "ht" "ht.el" (0 0 0 0)) +;;; Generated autoloads from ht.el + +(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "ht" 'nil)) + +;;;*** + +;; Local Variables: +;; version-control: never +;; no-byte-compile: t +;; no-update-autoloads: t +;; coding: utf-8 +;; End: +;;; ht-autoloads.el ends here diff --git a/elpa/ht-20180129.2234/ht-pkg.el b/elpa/ht-20180129.2234/ht-pkg.el new file mode 100644 index 00000000..d714285f --- /dev/null +++ b/elpa/ht-20180129.2234/ht-pkg.el @@ -0,0 +1,2 @@ +;;; -*- no-byte-compile: t -*- +(define-package "ht" "20180129.2234" "The missing hash table library for Emacs" '((dash "2.12.0")) :commit "5a665d00dc8fda77bad2a43277d8809c23e46ab8" :keywords '("hash table" "hash map" "hash") :authors '(("Wilfred Hughes" . "me@wilfred.me.uk")) :maintainer '("Wilfred Hughes" . "me@wilfred.me.uk")) diff --git a/elpa/ht-20140122.1555/ht.el b/elpa/ht-20180129.2234/ht.el similarity index 73% rename from elpa/ht-20140122.1555/ht.el rename to elpa/ht-20180129.2234/ht.el index d536a18d..3907e1e6 100644 --- a/elpa/ht-20140122.1555/ht.el +++ b/elpa/ht-20180129.2234/ht.el @@ -3,9 +3,10 @@ ;; Copyright (C) 2013 Wilfred Hughes ;; Author: Wilfred Hughes -;; Version: 20140122.1555 -;; X-Original-Version: 2.0 +;; Version: 2.3 +;; Package-Version: 20180129.2234 ;; Keywords: hash table, hash map, hash +;; Package-Requires: ((dash "2.12.0")) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -22,13 +23,13 @@ ;;; Commentary: -;; The missing hash table utility library for Emacs. +;; The missing hash table library for Emacs. ;; -;; See documentation on https://github.com/Wilfred/ht.el +;; See documentation at https://github.com/Wilfred/ht.el ;;; Code: -(eval-when-compile (require 'cl)) ;; dolist +(require 'dash) (defmacro ht (&rest pairs) "Create a hash table with the key-value pairs given. @@ -36,15 +37,22 @@ Keys are compared with `equal'. \(fn (KEY-1 VALUE-1) (KEY-2 VALUE-2) ...)" (let* ((table-symbol (make-symbol "ht-temp")) - (assignments - (mapcar - (lambda (pair) `(ht-set! ,table-symbol ,@pair)) - pairs))) + (assignments + (mapcar + (lambda (pair) `(ht-set! ,table-symbol ,@pair)) + pairs))) `(let ((,table-symbol (ht-create))) ,@assignments ,table-symbol))) -(defun ht-create (&optional test) +(defsubst ht-set! (table key value) + "Associate KEY in TABLE with VALUE." + (puthash key value table) + nil) + +(defalias 'ht-set 'ht-set!) + +(defsubst ht-create (&optional test) "Create an empty hash table. TEST indicates the function used to compare the hash @@ -52,9 +60,13 @@ keys. Default is `equal'. It can be `eq', `eql', `equal' or a user-supplied test created via `define-hash-table-test'." (make-hash-table :test (or test 'equal))) -(defun ht<-alist (alist) - "Create a hash table with initial values according to ALIST." - (let ((h (ht-create))) +(defun ht<-alist (alist &optional test) + "Create a hash table with initial values according to ALIST. + +TEST indicates the function used to compare the hash +keys. Default is `equal'. It can be `eq', `eql', `equal' or a +user-supplied test created via `define-hash-table-test'." + (let ((h (ht-create test))) ;; the first key-value pair in an alist gets precedence, so we ;; start from the end of the list: (dolist (pair (reverse alist) h) @@ -64,51 +76,32 @@ user-supplied test created via `define-hash-table-test'." (defalias 'ht-from-alist 'ht<-alist) -;; based on the excellent -partition from dash.el, but we aim to be self-contained -(defun ht/group-pairs (list) - "Return a new list with the items in LIST grouped into pairs. -Errors if LIST doesn't contain an even number of elements." - (let ((result) - (sublist) - (len 0)) - - (while list - ;; take the head of LIST and push onto SUBLIST - (setq sublist (cons (car list) sublist)) - (setq list (cdr list)) - - (setq len (1+ len)) - - (when (= len 2) - ;; push this two-item list onto RESULT - (setq result (cons (nreverse sublist) result)) - (setq sublist nil) - (setq len 0))) - - (when sublist (error "Expected an even number of elements")) - (nreverse result))) - -(defun ht<-plist (plist) - "Create a hash table with initial values according to PLIST." - (let ((h (ht-create))) - (dolist (pair (ht/group-pairs plist) h) +(defun ht<-plist (plist &optional test) + "Create a hash table with initial values according to PLIST. + +TEST indicates the function used to compare the hash +keys. Default is `equal'. It can be `eq', `eql', `equal' or a +user-supplied test created via `define-hash-table-test'." + (let ((h (ht-create test))) + (dolist (pair (nreverse (-partition 2 plist)) h) (let ((key (car pair)) (value (cadr pair))) (ht-set! h key value))))) (defalias 'ht-from-plist 'ht<-plist) -(defun ht-get (table key &optional default) +(defsubst ht-get (table key &optional default) "Look up KEY in TABLE, and return the matching value. If KEY isn't present, return DEFAULT (nil if not specified)." (gethash key table default)) -(defun ht-set! (table key value) - "Associate KEY in TABLE with VALUE." - (puthash key value table) - nil) - -(defalias 'ht-set 'ht-set!) +(defun ht-get* (table &rest keys) + "Look up KEYS in nested hash tables, starting with TABLE. +The lookup for each key should return another hash table, except +for the final key, which may return any value." + (if (cdr keys) + (apply #'ht-get* (ht-get table (car keys)) (cdr keys)) + (ht-get table (car keys)))) (defun ht-update! (table from-table) "Update TABLE according to every key-value pair in FROM-TABLE." @@ -127,13 +120,13 @@ table is used." (mapc (lambda (table) (ht-update! merged table)) tables) merged)) -(defun ht-remove! (table key) +(defsubst ht-remove! (table key) "Remove KEY from TABLE." (remhash key table)) (defalias 'ht-remove 'ht-remove!) -(defun ht-clear! (table) +(defsubst ht-clear! (table) "Remove all keys from TABLE." (clrhash table) nil) @@ -178,6 +171,14 @@ For every key-value pair in TABLE, evaluate FORM with the variables key and value bound." `(ht-each (lambda (key value) ,form) ,table)) +(defun ht-select-keys (table keys) + "Return a copy of TABLE with only the specified KEYS." + (let (result) + (setq result (make-hash-table :test (hash-table-test table))) + (dolist (key keys result) + (if (not (equal (gethash key table 'key-not-found) 'key-not-found)) + (puthash key (gethash key table) result))))) + (defun ht->plist (table) "Return a flat list '(key1 value1 key2 value2...) from TABLE. @@ -191,7 +192,7 @@ inverse of `ht<-plist'. The following is not guaranteed: (defalias 'ht-to-plist 'ht->plist) -(defun ht-copy (table) +(defsubst ht-copy (table) "Return a shallow copy of TABLE (keys and values are shared)." (copy-hash-table table)) @@ -218,11 +219,11 @@ inverse of `ht<-alist'. The following is not guaranteed: (defalias 'ht-contains-p 'ht-contains?) -(defun ht-size (table) +(defsubst ht-size (table) "Return the actual number of entries in TABLE." (hash-table-count table)) -(defun ht-empty? (table) +(defsubst ht-empty? (table) "Return true if the actual number of entries in TABLE is zero." (zerop (ht-size table))) @@ -277,5 +278,19 @@ FUNCTION is called with two arguments, KEY and VALUE." (throw 'break (list key value)))) table))) +(defun ht-equal? (table1 table2) + "Return t if TABLE1 and TABLE2 have the same keys and values. +Does not compare equality predicates." + (let ((keys1 (ht-keys table1)) + (keys2 (ht-keys table2)) + (sentinel (make-symbol "ht-sentinel"))) + (and (equal (length keys1) (length keys2)) + (--all? + (equal (ht-get table1 it) + (ht-get table2 it sentinel)) + keys1)))) + +(defalias 'ht-equal-p 'ht-equal?) + (provide 'ht) ;;; ht.el ends here -- 2.47.3