[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/trie c7c9994 015/111: trie--createfun now passed corres
From: |
Stefan Monnier |
Subject: |
[elpa] externals/trie c7c9994 015/111: trie--createfun now passed corresponding sequence as an argument |
Date: |
Mon, 14 Dec 2020 11:35:11 -0500 (EST) |
branch: externals/trie
commit c7c99942f2115cdd007becf61447088a547662e3
Author: Toby Cubitt <toby-predictive@dr-qubit.org>
Commit: tsc25 <toby-predictive@dr-qubit.org>
trie--createfun now passed corresponding sequence as an argument
superseding removed trie-depth variable.
Corrected descriptions of the function arguments in the trie-create-custom
docstring.
---
trie.el | 70 +++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 40 insertions(+), 30 deletions(-)
diff --git a/trie.el b/trie.el
index 4b34ba5..1ac4825 100644
--- a/trie.el
+++ b/trie.el
@@ -317,9 +317,9 @@ If START or END is negative, it counts from the end."
(:type vector)
(:constructor nil)
(:constructor trie--node-create
- (split trie
+ (split seq trie
&aux (subtree (funcall (trie--createfun trie)
- (trie--cmpfun trie)))))
+ (trie--cmpfun trie) seq))))
(:constructor trie--node-create-data
(data &aux (split trie--terminator) (subtree data)))
(:constructor trie--node-create-dummy
@@ -328,8 +328,7 @@ If START or END is negative, it counts from the end."
(createfun cmpfun
&aux
(split nil)
- (subtree (let ((trie-depth 0))
- (funcall createfun cmpfun)))))
+ (subtree (funcall createfun cmpfun []))))
(:copier nil))
split subtree)
@@ -683,7 +682,7 @@ STACK-EMPTYFUN, determine the type of trie that is created.
CREATEFUN is called as follows:
- (CREATEFUN COMPARISON-FUNCTION)
+ (CREATEFUN COMPARISON-FUNCTION SEQ)
and should return a data structure (\"ARRAY\") that can be used
as an associative array, where two elements A and B are equal if
@@ -692,32 +691,46 @@ the following is non-nil:
(and (COMPARISON-FUNCTION b a)
(COMPARISON-FUNCTION b a))
-When CREATEFUN is called, the depth in the trie at which the
-associative array is being created can be accessed via the
-variable `trie-depth'. This can be used, for example, to create
-hybrid trie structures in which different types of associative
-array are used at different depths in the trie. (Note that, in
-this case, all the other functions described below must be able
-to correctly handle *any* of these types of associate array.)
+The SEQ argument is a vector containing the sequence that will
+correspond to the newly created array in the trie. For most types
+of trie, this value is ignored. It is passed to CREATEFUN only in
+order to allow the creation of \"hybrid\" trie structures, in
+which different types of associative array are used in different
+parts of the trie. For example, the type of associative array
+could be chosen based on the depth in the trie, given by \(length
+SEQ\). (Note that all the other functions described below must be
+able to correctly handle *any* of the types of associate array
+that might be created by CREATEFUN.)
INSERTFUN, DELETEFUN, LOOKUPFUN, MAPFUN and EMPTYFUN should
insert, delete, lookup, map over, and check-if-there-exist-any
-elements in the associative array. They are called as follows:
+elements in an associative array. They are called as follows:
(INSERTFUN array element &optional updatefun)
- (DELETEFUN array element)
+ (DELETEFUN array element &optional predicate nilflag)
(LOOKUPFUN array element &optional nilflag)
(MAPFUN function array &optional reverse)
(EMPTYFUN array)
-INSERTFUN should return the new element, which will be ELEMENT
-itself unless UPDATEFUN is specified. In the latter case, it
-should pass two arguments to UPDATEFUN, ELEMENT and the matching
-element in the associate array, and replace that element with the
-return value.
+INSERTFUN should insert ELEMENT into ARRAY and return the new
+element, which will be ELEMENT itself unless UPDATEFUN is
+specified. In that case, if and only if an element matching
+ELEMENT already exists in the associative array, INSERTFUN should
+instead pass ELEMENT and the matching element as arguments to
+UPDATEFUN, replace the matching element with the return value,
+and return that return value.
+
+DELETEFUN should delete the element in the associative array that
+matches ELEMENT, and return the deleted element. However, if
+PREDICATE is specified and a matching element exists in ARRAY,
+DELETEFUN should first pass the matching element as an argument
+to PREDICATE before deleting, and should only delete the element
+if PREDICATE returns non-nil. DELETEFUN should return NILFLAG if
+no element was deleted (either becuase no matching element was
+found, or because TESTFUN returned nil).
LOOKUPFUN should return the element from the associative array
-that is equal to ELEMENT, or NILFLAG if no match exists.
+that matches ELEMENT, or NILFLAG if no matching element exists.
MAPFUN should map FUNCTION over all elements in the order defined by
COMPARISON-FUNCTION, or in reverse order if REVERSE is non-nil.
@@ -736,14 +749,15 @@ successive calls to
(STACK-POPFUN stack)
should return elements from the associative array in the order
-defined by COMPARISON-FUNCTION.
+defined by COMPARISON-FUNCTION, and
(STACK-EMPTYFUN stack)
should return non-nil if the stack is empty, nil otherwise.
-Note: to avoid nasty dynamic scoping bugs, the supplied functions
-must *not* bind any variables with names commencing \"--\".")
+
+Warning: to avoid nasty dynamic scoping bugs, the supplied
+functions must *never* bind any variables with names commencing \"--\".")
@@ -1036,14 +1050,12 @@ Note: to avoid nasty dynamic scoping bugs, UPDATEFUN
must *not*
bind any variables with names commencing \"--\"."
(if (trie--print-form trie)
(error "Attempted to operate on trie that is in print-form")
- ;; absurb variable names are an attempt to avoid dynamic scoping bugs
+ ;; absurd variable names are an attempt to avoid dynamic scoping bugs
(let ((--trie-insert--updatefun updatefun)
--trie-insert--old-node-flag
- (trie-depth 0)
(node (trie--root trie))
(len (length key))
(i -1))
- (declare (special trie-depth))
;; Descend trie, adding nodes for non-existent elements of KEY. The
;; update function passed to `trie--insertfun' ensures that existing
;; nodes are left intact.
@@ -1051,11 +1063,9 @@ bind any variables with names commencing \"--\"."
(setq --trie-insert--old-node-flag nil)
(setq node (funcall (trie--insertfun trie)
(trie--node-subtree node)
- (let ((trie-depth (1+ trie-depth)))
- (trie--node-create (elt key i) trie))
+ (trie--node-create (elt key i) key trie)
(lambda (a b)
- (setq --trie-insert--old-node-flag t) b)))
- (incf trie-depth))
+ (setq --trie-insert--old-node-flag t) b))))
;; Create or update data node.
(setq node (funcall (trie--insertfun trie)
(trie--node-subtree node)
- [elpa] externals/trie 1eb515f 078/111: Implement trie fuzzy match and completion stacks., (continued)
- [elpa] externals/trie 1eb515f 078/111: Implement trie fuzzy match and completion stacks., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 3b7aa3c 082/111: Document that fuzzy queries with distance 0 won't work., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 53146c1 080/111: Implement fuzzy match and completion on dict-trees., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 81268ae 012/111: Added functions for pushing things onto dictree and trie stacks, Stefan Monnier, 2020/12/14
- [elpa] externals/trie a402c27 021/111: Implemented wildcard searches!, Stefan Monnier, 2020/12/14
- [elpa] externals/trie e505b47 039/111: Pass equality function constructed from trie comparison function to tNFA functions, Stefan Monnier, 2020/12/14
- [elpa] externals/trie a35651b 029/111: Implemented grouping constructs in trie wildcards, Stefan Monnier, 2020/12/14
- [elpa] externals/trie a8615f7 052/111: Bug-fixes to edebug pretty-print functions., Stefan Monnier, 2020/12/14
- [elpa] externals/trie a1f9faa 044/111: Re-filled to 72 chars/line, for mailing to gnu-emacs-sources list, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 13bb42f 042/111: Updated docstrings for regexp-related functions and others., Stefan Monnier, 2020/12/14
- [elpa] externals/trie c7c9994 015/111: trie--createfun now passed corresponding sequence as an argument,
Stefan Monnier <=
- [elpa] externals/trie da9ace9 051/111: More efficient implementations of replacements for CL 'position' function., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 0d17008 037/111: Added nilflag argument to trie-stack functions, Stefan Monnier, 2020/12/14
- [elpa] externals/trie f930fe9 027/111: Documentation updates related to wildcard searches and predictive features that make use of them, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 46369a7 026/111: Added trie-wildcard-match function, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 7823234 095/111: Fix bug in trie-fuzzy-complete that meant it didn't return minimum prefix distance in some cases., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 5fa968c 093/111: Fix byte-compiler warning., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 87d5786 102/111: Allow trie-fuzzy-match/complete to take lists of multiple prefixes/strings., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 71f8273 098/111: Significantly improve efficiency of trie-fuzzy-complete., Stefan Monnier, 2020/12/14
- [elpa] externals/trie c2b5e26 105/111: Myriad bug fixes and code refactoring in new fuzzy and ngram completion., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 63da3b1 111/111: * trie.el: Fix header which likely suffered a `M-q` accident, Stefan Monnier, 2020/12/14