Permalink
Browse files

kmp.lisp: Tweak the higher lever interface.

  • Loading branch information...
1 parent 42122a0 commit 7a0d974724a1709493ce7808ecddc44b310f0d6d @stassats committed Sep 21, 2010
Showing with 9 additions and 5 deletions.
  1. +9 −5 kmp.lisp
View
@@ -58,18 +58,22 @@
((= (incf i) pattern-length)
(return m))))))))
-(defun kmp (pattern sequence &key (case-insensitive t))
- (declare (type simple-string sequence pattern))
+(defun kmp (pattern string &key (case-insensitive t))
+ (declare (type simple-string string pattern))
(let ((sub-length (length pattern))
- (length (length sequence)))
+ (length (length string)))
(cond ((= sub-length 1)
- (position (elt pattern 0) sequence))
+ (position (elt pattern 0) string
+ :test
+ (if case-insensitive
+ #'char-equal
+ #'char=)))
((= sub-length 0)
0)
((> sub-length length)
nil)
(t
(do-kmp pattern (when case-insensitive
(reverse-case pattern))
- sequence
+ string
(build-table pattern))))))

0 comments on commit 7a0d974

Please sign in to comment.