From 18ad0a04b64aeb239c348e64a238b66f6895d81e Mon Sep 17 00:00:00 2001 From: kalmar Date: Thu, 6 Jul 2017 09:18:53 +0200 Subject: [PATCH] replace_all! returns if any modification has been performed --- src/Groups.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Groups.jl b/src/Groups.jl index 4b3339b..2d0aae2 100644 --- a/src/Groups.jl +++ b/src/Groups.jl @@ -352,15 +352,17 @@ function replace(W::GWord, index, toreplace::GWord, replacement::GWord) end function replace_all!{T}(W::GWord{T}, subst_dict::Dict{GWord{T}, GWord{T}}) + modified = false for toreplace in reverse!(sort!(collect(keys(subst_dict)), by=length)) replacement = subst_dict[toreplace] i = findfirst(W, toreplace) while i ≠ 0 + modified = true replace!(W,i,toreplace, replacement) i = findnext(W, toreplace, i) end end - return W + return modified end replace_all{T<:GSymbol}(W::GWord{T}, subst_dict::Dict{GWord{T}, GWord{T}}) = replace_all!(deepcopy(W), subst_dict)