Commits

Anonymous committed adc7ddc

Some refactoring

  • Participants
  • Parent commits 76c7c86

Comments (0)

Files changed (1)

 (define (make-trie)
   (%make-trie (list) (list)))
 
-(define (add-child! trie key child)
-  (trie-children-set!
-   trie (alist-cons key child (trie-children trie))))
-
-(define (trie-insert! trie key val)
-  (let loop ((node trie)
-             (key key))
-    (if (null? key)
-        (trie-value-set! node (list val))
-        (let* ((ckey (car key))
-               (child (or (alist-ref ckey (trie-children node))
-                          (let ((child (make-trie)))
-                            (add-child! node ckey child)
-                            child))))
-          (loop child (cdr key)))))
-  (void))
-
 (define (trie-ref* trie key)
   (alist-ref key (trie-children trie)))
 
               (loop child (cdr key))
               (default))))))
 
+(define (add-child! trie key child)
+  (trie-children-set!
+   trie (alist-cons key child (trie-children trie))))
+
+(define (trie-insert! trie key val)
+  (let loop ((node trie)
+             (key key))
+    (if (null? key)
+        (trie-value-set! node (list val))
+        (let* ((ckey (car key))
+               (child (or (trie-ref* node ckey)
+                          (let ((child (make-trie)))
+                            (add-child! node ckey child)
+                            child))))
+          (loop child (cdr key))))))
 
 (define (trie->list trie)
   (cons