Recently Written · git

len-cmp

Efficient comparsion of length in lists.

git clone https://github.com/equwal/len-cmp

Log | Files | Refs


README.org (592 bytes)

1 #+TITLE: Length Comparison
2 #+AUTHOR: Spenser Truex
3 #+EMAIL: web@spensertruex.com
4 #+OPTIONS: tex:t
5 * Purpose
6 Provide /short-circuit/ length comparisons.
7 * Usage
8 The only external function is `len`.
9 #+BEGIN_SRC common-lisp
10 (len <integer or list> <list> &optional (<predicate> #'=))
11 (len 3 '(1 2 3)) ;=> T
12 (len '(a b c) '(1 2 3)) ;=> T
13 (len 3 '(1 2 3) #'/=) ;=> NIL
14 #+END_SRC
15 * Complexity
16 Comparing the length of some lists with lengths in *L* is O(sum(*L*)).
17 With a short-circuit length comparsion, the worst case scenario is the same, 
18 with the best case O(1) and average case of O(min(*L*)).