emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/trie 0d17008 037/111: Added nilflag argument to trie-st


From: Stefan Monnier
Subject: [elpa] externals/trie 0d17008 037/111: Added nilflag argument to trie-stack functions
Date: Mon, 14 Dec 2020 11:35:15 -0500 (EST)

branch: externals/trie
commit 0d17008b3e7d41c5e4ffbe0bd5d53fb6df498abd
Author: Toby Cubitt <toby-predictive@dr-qubit.org>
Commit: tsc25 <toby-predictive@dr-qubit.org>

    Added nilflag argument to trie-stack functions
---
 trie.el | 59 ++++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 40 insertions(+), 19 deletions(-)

diff --git a/trie.el b/trie.el
index 7bd693b..8cd03bb 100644
--- a/trie.el
+++ b/trie.el
@@ -1094,15 +1094,20 @@ is better to use one of those instead."
     (trie--stack-create trie type reverse)))
 
 
-(defun trie-stack-pop (trie-stack)
+(defun trie-stack-pop (trie-stack &optional nilflag)
   "Pop the first element from TRIE-STACK.
-Returns nil if the stack is empty."
-  ;; if elements have been pushed onto the stack, pop those first
-  (if (trie--stack-pushed trie-stack)
-      (pop (trie--stack-pushed trie-stack))
-    ;; otherwise, pop first element from trie-stack and repopulate it
-    (let ((first (pop (trie--stack-store trie-stack))))
-      (when first
+
+Returns nil if the stack is empty, or NILFLAG if specified. (The
+latter allows an empty stack to be distinguished from a null
+element stored in the trie.)"
+  ;; return nilflag if stack is empty
+  (if (trie-stack-empty-p trie-stack)
+      nilflag
+    ;; if elements have been pushed onto the stack, pop those first
+    (if (trie--stack-pushed trie-stack)
+       (pop (trie--stack-pushed trie-stack))
+      ;; otherwise, pop first element from trie-stack and repopulate it
+      (let ((first (pop (trie--stack-store trie-stack))))
        (setf (trie--stack-store trie-stack)
              (funcall (trie--stack-repopulatefun trie-stack)
                       (trie--stack-store trie-stack)
@@ -1120,14 +1125,21 @@ Returns nil if the stack is empty."
   (push element (trie--stack-pushed trie-stack)))
 
 
-(defun trie-stack-first (trie-stack)
+(defun trie-stack-first (trie-stack &optional nilflag)
   "Return the first element from TRIE-STACK, without removing it
-from the stack. Returns nil if the stack is empty."
-  ;; if elements have been pushed onto the stack, return first of those
-  (if (trie--stack-pushed trie-stack)
-      (car (trie--stack-pushed trie-stack))
-    ;; otherwise, return first element from trie-stack
-    (car (trie--stack-store trie-stack))))
+from the stack.
+
+Returns nil if the stack is empty, or NILFLAG if specified. (The
+latter allows an empty stack to be distinguished from a null
+element stored in the trie.)"
+  ;; return nilflag if stack is empty
+  (if (trie-stack-empty-p trie-stack)
+      nilflag
+    ;; if elements have been pushed onto the stack, return first of those
+    (if (trie--stack-pushed trie-stack)
+       (car (trie--stack-pushed trie-stack))
+      ;; otherwise, return first element from trie-stack
+      (car (trie--stack-store trie-stack)))))
 
 
 (defalias 'trie-stack-p 'trie--stack-p
@@ -1529,9 +1541,8 @@ it is better to use one of those instead."
   `(cdr ,el))
 
 
-
 ;;; ----------------------------------------------------------------
-;;;                 The public search functions
+;;;            The public wildcard search functions
 
 (defun trie-wildcard-match (pattern sequence cmpfun)
   "Return t if wildcard PATTERN matches SEQ, nil otherwise.
@@ -1951,7 +1962,6 @@ first!."
 
 
 
-
 ;;; ------------------------------------------------------------------
 ;;;              Internal functions (do the real work)
 
@@ -2036,6 +2046,9 @@ first!."
 
 
 
+;;; ------------------------------------------------------------------
+;;;                      wildcard search
+
 (defun trie--wildcard-construct-rankfun (trie pattern rankfun reverse)
   ;; construct appropriate rank function for wildcard search, and return a
   ;; list containing the rankfun and a flags indicating whether to expect
@@ -2318,6 +2331,8 @@ non-terminal * wildcards are not supported"))
 
 
 
+;;; ------------------------------------------------------------------
+;;;                      wildcard stack
 
 ;; FIXME: using a defstruct instead of these macros causes *very* weird
 ;;        bugs...why?!?!?!!!
@@ -2338,7 +2353,7 @@ non-terminal * wildcards are not supported"))
 ;;    (:type vector)
 ;;    (:constructor nil)
 ;;    (:constructor trie--wildcard-stack-el-create
-;;              (seq pattern node idx group-stack groups))
+;;                 (seq pattern node idx group-stack groups))
 ;;    (:copier nil))
 ;;   seq pattern node idx group-stack groups)
 
@@ -2634,6 +2649,12 @@ non-terminal * wildcards are not supported"))
 
 
 
+
+;; ================================================================
+;;                        Regexp search
+
+
+
 (provide 'trie)
 
 ;;; trie.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]