1. Dmitry Grebeniuk
  2. cadastr

Commits

Dmitry Grebeniuk  committed d6fbf7f

+ trie#dump

  • Participants
  • Parent commits 02422ca
  • Branches default

Comments (0)

Files changed (1)

File src/cadastr.ml

View file
 
 
     class trie ['k, 'v]
+    ?ti_key
+    ?ti_val
     (node_list : list 'v)
     (level : Tfun.map_rws 'k (trie 'k 'v)) =
       object (self)
         method get_root_node = node_list;
         method get_level = level;
 
-        method empty = new trie [] level#empty;
+        method empty = new trie ?ti_key ?ti_val [] level#empty;
         method is_empty = ((node_list = []) && level#is_empty);
 
         method merge_levels
             let n1 = self#get_root_node
             and n2 = t2#get_root_node in
 
-            new trie
+            new trie ?ti_key ?ti_val
               (if n1 == [] && n2 == [] then [] else merge_node kr n1 n2)
               (self#merge_levels merge_node kr self#get_level t2#get_level)
         ;
               if pair == pair'
                  || (node_list == node_list' && level == level')
               then raise Dont_rebuild
-              else new trie node_list' level'
+              else new trie ?ti_key ?ti_val node_list' level'
           | [hk :: tk] ->
               let old_subtrie =
                 match level#get_opt hk with
               in
               let new_subtrie = old_subtrie#rebuild tk ~update
               in
-                new trie node_list
+                new trie ?ti_key ?ti_val node_list
                   (if new_subtrie#is_empty
                    then level#remove hk
                    else level#replace hk new_subtrie)
             self#fold_prefix f init []
         ;
 
+        method dump
+        : unit -> string
+        = fun () ->
+          String.concat ""
+            (List.rev
+               (self#fold
+                 (fun acc_rev k v ->
+                    let ktxt =
+                      (String.concat "/"
+                         (List.map
+                            (match ti_key with
+                             [ None -> fun _ -> "<key_abstract>"
+                             | Some t -> t#show
+                             ]
+                            )
+                            k
+                         )
+                      ) in
+                    let vtxt =
+                      match ti_val with
+                      [ None -> "<val_abstract>"
+                      | Some t -> t#show v
+                      ]
+                    in
+                      [ Printf.sprintf "%S => %s\n" ktxt vtxt
+                      :: acc_rev
+                      ]
+                 )
+                 []
+               )
+            )
+        ;
+
       end
     ;