aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stack-core.el23
-rw-r--r--test/tests.el32
2 files changed, 7 insertions, 48 deletions
diff --git a/stack-core.el b/stack-core.el
index 45d7cb3..9a535cd 100644
--- a/stack-core.el
+++ b/stack-core.el
@@ -225,8 +225,13 @@ entire response as a complex alist."
(delq
nil
(mapcar (lambda (cons-cell)
- (let ((f (stack-core-filter-data--item-in-tree
- (car cons-cell) desired-tree)))
+ ;; TODO the resolution of `f' is O(2n) in the worst
+ ;; case. It may be faster to implement the same
+ ;; functionality as a `while' loop to stop looking the
+ ;; list once it has found a match. Do speed tests.
+ ;; See edfab4443ec3d376c31a38bef12d305838d3fa2e.
+ (let ((f (or (memq (car cons-cell) desired-tree)
+ (assoc (car cons-cell) desired-tree))))
(when f
(if (and (sequencep (cdr cons-cell))
(sequencep (elt (cdr cons-cell) 0)))
@@ -236,19 +241,5 @@ entire response as a complex alist."
cons-cell))))
data))))
-(defun stack-core-filter-data--item-in-tree (item tree)
- "Check if ITEM is in the direct leaves of TREE
-
-For example, when called with (f 'item '(some item here)), the
-return would be `t'. When called as (f 'item '(some (item here)
-in a (deep structure))), `(item here)' would be returned.
-"
- (when tree
- (if (equal item (car tree)) tree
- (if (and (listp (car tree))
- (equal item (caar tree)))
- (car tree)
- (stack-core-filter-data--item-in-tree item (cdr tree))))))
-
(provide 'stack-core)
;;; stack-core.el ends here
diff --git a/test/tests.el b/test/tests.el
index ac40cea..44b0de0 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -75,35 +75,3 @@
((should-not-go))
((1 . alpha) (2 . beta))]
'(1 2 3)))))
-
-(ert-deftest test-tree-member ()
- "`stack-core-filter-data--item-in-tree'"
- (should
- (equal
- '(a b c)
- (stack-core-filter-data--item-in-tree 'a '(a b c))))
-
- (should
- (equal
- '(a b c)
- (stack-core-filter-data--item-in-tree 'a '(b a b c))))
-
- (should
- (equal
- '(a b c)
- (stack-core-filter-data--item-in-tree 'a '((a b c) 1 2))))
-
- (should
- (equal
- '(a b c)
- (stack-core-filter-data--item-in-tree 'a '(1 (a b c) 2))))
-
- (should
- (equal
- '(a b c)
- (stack-core-filter-data--item-in-tree 'a '(1 2 (a b c)))))
-
- (should
- (equal
- '(a a b c)
- (stack-core-filter-data--item-in-tree 'a '(1 (a a b c) 2)))))