Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

kmp.lisp: Tweak the higher lever interface.

  • Loading branch information...
commit 7a0d974724a1709493ce7808ecddc44b310f0d6d 1 parent 42122a0
@stassats authored
Showing with 9 additions and 5 deletions.
  1. +9 −5 kmp.lisp
View
14 kmp.lisp
@@ -58,12 +58,16 @@
((= (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)
@@ -71,5 +75,5 @@
(t
(do-kmp pattern (when case-insensitive
(reverse-case pattern))
- sequence
+ string
(build-table pattern))))))
Please sign in to comment.
Something went wrong with that request. Please try again.