diff --git a/src/Trie.ml b/src/Trie.ml index c1ca76ed..c893ad1b 100644 --- a/src/Trie.ml +++ b/src/Trie.ml @@ -317,6 +317,8 @@ let[@inline] retag t : _ t -> _ t = | None -> None | Some (d, _) -> non_empty @@ mk_node' d (Some t) +let[@inline] untag t = retag () t + let retag_subtree path t (v : _ t) : _ t = update_subtree path (retag t) v let rec iter_tag_node (f : 'a -> unit) (t : 'a tag_node) = diff --git a/src/Trie.mli b/src/Trie.mli index 4ce947b0..73c08155 100644 --- a/src/Trie.mli +++ b/src/Trie.mli @@ -158,6 +158,9 @@ val of_seq_with_merger : ?prefix:bwd_path -> (bwd_path -> 'data * 'tag -> 'data (** [retag tag t] changes all tags within [t] to [tag] in O(1) time. The data remain intact. *) val retag : 'tag -> ('data, _) t -> ('data, 'tag) t +(** [untag t] is [retag () t]. *) +val untag : ('data, _) t -> ('data, unit) t + (** [retag_subtree tag path t] changes all tags within the subtrie rooted at [path] to [tag] efficiently. The data remain intact. *) val retag_subtree : path -> 'tag -> ('data, 'tag) t -> ('data, 'tag) t diff --git a/test/ListAsTrie.ml b/test/ListAsTrie.ml index 2841ee0a..e2c977fd 100644 --- a/test/ListAsTrie.ml +++ b/test/ListAsTrie.ml @@ -100,6 +100,7 @@ let of_seq s = Seq.fold_left (union_singleton ~prefix:Emp (fun _ _ y -> y)) empt let of_seq_with_merger ?(prefix=Emp) m s = Seq.fold_left (union_singleton ~prefix m) empty s let retag t l = List.map (fun (p, (d, _)) -> p, (d, t)) l +let untag l = retag () l let retag_subtree pre t l = List.map (fun ((p, (d, _)) as b) -> if Option.is_some (split_path pre p) then p, (d, t) else b) l let set_of_tags cmp l = List.to_seq @@ List.sort_uniq cmp @@ List.map (fun (_, (_, t)) -> t) l