Xah Talk Show 2025-07-05 Ep675 Golang vs Emacs Lisp Hashtable. Part 2

xah talk show ep675 1c407
xah talk show ep675 1c407
;; -*- coding: utf-8; lexical-binding: t; -*-

;; Create a hashtable, each key is a full file path of a dir, including subdirectory.
;; But excluding a given list of dir names.
;; then, test speed by go thru the hashtable, check each key existance

(setq starttime (format-time-string "%s") )

(setq xinputdir "c:/Users/xah/web/" )
(setq xdir-names-ignore-list
      '(
        ".git"
        "emacs_manual"
        "js_es2011"
        "js_es2015"
        "node_api"
        ))

;; HHHH------------------------------

(setq
 xfilelist
 (directory-files-recursively
  xinputdir
  ""
  nil
  (lambda (x)
    (let ((xdirname (file-name-nondirectory x)))
      (seq-every-p
       (lambda (ignorename)
         (if (string-equal xdirname ignorename) nil t))
       xdir-names-ignore-list)))))

;; create a hash table
(setq xtable (make-hash-table :test 'equal))

(mapc
 (lambda (x)
   (puthash x 1 xtable))
 xfilelist)

;; HHHH------------------------------

(setq endtime (format-time-string "%s") )

;; HHHH------------------------------
;; print

(let (newbuf)
  (setq newbuf (get-buffer-create "*xtable output*"))
  (with-output-to-temp-buffer newbuf
    (print (format "time spent: %s"
                   (- (string-to-number endtime) (string-to-number starttime))))
    (print (format "total items: %s" (hash-table-count xtable)))
    (princ (let (xlist)
             (maphash (lambda (k _) (push (format "%s" k) xlist)) xtable)
             (mapconcat 'identity xlist "\n"))))
  (switch-to-buffer newbuf))

hashtable fight