Changeset 25759 in project
- Timestamp:
- 01/05/12 04:48:59 (9 years ago)
- Location:
- release/4/suffix-tree
- Files:
-
- 3 deleted
- 1 edited
- 3 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
release/4/suffix-tree/trunk/suffix-tree.scm
r25758 r25759 1 1 ;; 2 2 ;; 3 ;; An implementation of tries, a data type for representing sets of4 ;; lists efficiently, provided there is an ordering relation on the5 ;; elements of lists.3 ;; An implementation of suffix tree, a data structure for representing 4 ;; sets of lists efficiently, provided there is an ordering relation 5 ;; on the elements of lists. 6 6 ;; 7 7 ;; Copyright 2011 Ivan Raikov and the Okinawa Institute of Science and … … 9 9 ;; 10 10 ;; 11 ;; A trie is a tree with arcs labeled by elements from the element12 ;; type of the lists and with branches ordered on the basis of their13 ;; arc labels; moreover, only one branch per distinct label value is14 ;; allowed per node. Ends of lists are designated by an "EOL" marker;15 ;; a value may be associated with the EOL symbol.16 ;; 17 ;; 18 19 (module trie11 ;; A suffix tree is a tree with arcs labeled by elements from the 12 ;; element type of the lists and with branches ordered on the basis of 13 ;; their arc labels; moreover, only one branch per distinct label 14 ;; value is allowed per node. Ends of lists are designated by an 15 ;; "EOL" marker; a value may be associated with the EOL symbol. 16 ;; 17 ;; 18 19 (module suffix-tree 20 20 21 ( make- trie trie-equal? )21 ( make-suffix-tree suffix-tree-equal? ) 22 22 23 23 (import scheme chicken) … … 35 35 (branches (list-of branch?)))) 36 36 37 (define trie? (list-of branch?))38 39 40 (define ( trie-equal? t1 t2)37 (define suffix-tree? (list-of branch?)) 38 39 40 (define (suffix-tree-equal? t1 t2) 41 41 (let ((t1 (t1 'repr)) (t2 (t2 'repr))) 42 42 (let ((aeq (car t1)) (tr1 (caddr t1)) … … 54 54 55 55 56 (define (make- trie leq key->list . rest)56 (define (make-suffix-tree leq key->list . rest) 57 57 58 58 (let-optionals rest ((tr '())) 59 59 60 (assert ( trie? tr))60 (assert (suffix-tree? tr)) 61 61 62 62 (define empty '()) … … 120 120 )) 121 121 122 ;; Removes lst from tr. Any branches having a null sub trie122 ;; Removes lst from tr. Any branches having a null subsuffix-tree 123 123 ;; associated with them are deleted. 124 124 … … 143 143 144 144 ;; Merges tr1 and tr2. If there is a list that appears in both 145 ;; tries, an exception is raised.145 ;; suffix-trees, an exception is raised. 146 146 147 147 (define (merge tr1 tr2) … … 152 152 153 153 (((($ branch 'EOL b1) . _) (($ branch 'EOL _) . _)) 154 (error "already in trie" tr1 tr2))154 (error "already in suffix-tree" tr1 tr2)) 155 155 156 156 (((($ branch 'EOL b1) . tr11) tr2) … … 170 170 171 171 172 ;; Splits tr into three tries on the basis of a. The first trie172 ;; Splits tr into three suffix-trees on the basis of a. The first suffix-tree 173 173 ;; consists of branches headed by actions less than a (plus any EOL 174 174 ;; symbol), the second contains the branch (if any) associated with a, … … 199 199 200 200 ((insert) 201 (lambda (k bval) (make- trie leq key->list (insert (key->list k) bval tr))))201 (lambda (k bval) (make-suffix-tree leq key->list (insert (key->list k) bval tr)))) 202 202 203 203 ((lookup) … … 207 207 (lambda (k) 208 208 (let ((v (lookup (key->list k) tr identity))) 209 (if ( trie? v)210 (make- trie leq key->list v)209 (if (suffix-tree? v) 210 (make-suffix-tree leq key->list v) 211 211 v)))) 212 212 213 213 ((remove) 214 (lambda (k) (make- trie leq key->list (remove (key->list k) tr))))214 (lambda (k) (make-suffix-tree leq key->list (remove (key->list k) tr)))) 215 215 216 216 ((merge) 217 (lambda (x) (make- trie leq key->list (merge tr x))))217 (lambda (x) (make-suffix-tree leq key->list (merge tr x)))) 218 218 219 219 ((partition) -
release/4/suffix-tree/trunk/tests/run.scm
r25594 r25759 1 (use trie)1 (use suffix-tree) 2 2 3 (define t (make- trie char=? string->list ))3 (define t (make-suffix-tree char=? string->list )) 4 4 5 5 (define t1 ((t 'insert) "key1" 'test1)) … … 13 13 (assert (equal? 'test1 ((t3 'lookup) "1"))) 14 14 (assert (equal? 'test2 ((t3 'lookup) "2"))) 15 16 17
Note: See TracChangeset
for help on using the changeset viewer.