emasaka (owner)

Revisions

gist: 234589 Download_button fork
public
Public Clone URL: git://gist.github.com/234589.git
Embed All Files: show embed
kanzen-modoki-trie.el #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(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) ) ))))