Created
November 14, 2009 15:56
-
-
Save emasaka/234589 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun trie-add (trie key-str val) | |
(if (= (length key-str) 0) | |
trie | |
(let ((lst (split-string key-str "" t))) | |
(rplacd (last lst) val) | |
(trie-add::merge trie lst) ))) | |
(defun trie-add::merge (trie lst) | |
(cond ((null lst) trie) | |
((null trie) lst) | |
((atom (car trie)) | |
(if (string= (car trie) (car lst)) | |
(cons (car trie) | |
(trie-add::merge (cdr trie) (cdr lst)) ) | |
(list (list trie lst)) )) | |
(t | |
(let (r flg) | |
(setq r (mapcar #'(lambda (x) | |
(if (string= (car x) (car lst)) | |
(progn | |
(setq flg t) | |
(trie-add::merge x lst) ) | |
x )) | |
(car trie) )) | |
(cons (if flg r (cons lst (car trie))) | |
(cdr trie) ) )))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment