mcrl2/atermpp/algorithm.h¶

Include file:

#include "mcrl2/atermpp/algorithm.h"


Algorithms for ATerms.

Classes¶

• atermpp::detail::bottom_up_replace_aterm_builder

• atermpp::detail::cached_bottom_up_replace_aterm_builder

• atermpp::detail::partial_replace_aterm_builder

• atermpp::detail::replace_aterm_builder

Functions¶

Term atermpp::bottom_up_replace(Term t, ReplaceFunction r)

Replaces each subterm x of t by r(x). The ReplaceFunction r has the following signature: aterm_appl x; aterm_appl result = r(x); The replacements are performed in bottom up order. For example, replace(f(f(x)), f(x), x) returns x.

Parameters:

• t A term

• r The replace function that is applied to subterms.

Returns: The result of the replacement.

Term atermpp::bottom_up_replace(Term t, const aterm_appl &old_value, const aterm_appl &new_value)

Replaces each subterm in t that is equal to old_value with new_value. The replacements are performed in top down order. For example, replace(f(f(x)), f(x), x) returns f(x) and not x.

Parameters:

• t A term

• old_value The value of the subterm that is replaced.

• new_value The value that is substituted.

Returns: The result of the replacement.

Term atermpp::bottom_up_replace(Term t, ReplaceFunction r, std::unordered_map<aterm_appl, aterm> &cache)

Replaces each subterm x of t by r(x). The ReplaceFunction r has the following signature: aterm_appl x; aterm_appl result = r(x); The replacements are performed in bottom up order. For example, replace(f(f(x)), f(x), x) returns x.

Parameters:

• t A term

• r The replace function that is applied to subterms.

• cache A cache for the result of aterm_appl terms.

Returns: The result of the replacement.

void atermpp::find_all_if(const Term &t, MatchPredicate match, OutputIterator destBegin)

Finds all subterms of t that match a given predicate, and writes the found terms to the destination range starting with destBegin.

Parameters:

• t A term

• match The predicate that determines if a subterm is a match

• destBegin The iterator range to which output is written.

aterm_appl atermpp::find_if(const Term &t, MatchPredicate match)

Finds a subterm of t that matches a given predicate.

Parameters:

• t A term

• match The predicate that determines if a subterm is a match

Returns: A subterm that matches the given predicate, or aterm_appl() if none was found.

UnaryFunction atermpp::for_each(Term t, UnaryFunction op)

Calls op(elem) for subterms of the term t.

Parameters:

• t A term

• op The operation that is applied to subterms

Returns: a copy of the (internally modified) op. The function op must have the signature bool op(aterm_appl t). When op(t) is false, the children of t are skipped.

void atermpp::partial_find_all_if(Term t, MatchPredicate match, StopPredicate stop, OutputIterator destBegin)

Finds all subterms of t that match a given predicate, and writes the found terms to the destination range starting with destBegin. The term is only partially traversed. If the stop predicate returns true in a subterm, the recursion is not continued.

Parameters:

• t A term

• match The predicate that determines if a subterm is a match

• stop The predicate that determines if the recursion should not be continued in a subterm

• destBegin The iterator range to which output is written.

aterm_appl atermpp::partial_find_if(Term t, MatchPredicate match, StopPredicate stop)

Finds a subterm of t that matches a given predicate. The term is only partially traversed. If the stop predicate returns true in a subterm, the recursion is not continued.

Parameters:

• t A term

• match The predicate that determines if a subterm is a match

• stop The predicate that determines if the recursion should not be continued in a subterm

Returns: A subterm that matches the given predicate, or aterm_appl() if none was found.

Term atermpp::partial_replace(Term t, ReplaceFunction r)

Replaces subterms x of t by r(x). The replace function r returns an additional boolean value. This value is used to prevent further recursion. The ReplaceFunction r has the following signature: aterm_appl x; std::pair<aterm_appl, bool> result = r(x); result.first is the result r(x) of the replacement result.second denotes if the recursion should be continued The replacements are performed in top down order.

Parameters:

• t A term

• r The replace function that is applied to subterms.

Returns: The result of the replacement.

Term atermpp::replace(const Term &t, ReplaceFunction r)

Replaces each subterm x of t by r(x). The ReplaceFunction r has the following signature: aterm_appl x; aterm_appl result = r(x); The replacements are performed in top down order.

Parameters:

• t A term

• r The replace function that is applied to subterms.

Returns: The result of the replacement.

Term atermpp::replace(const Term &t, const aterm &old_value, const aterm &new_value)

Replaces each subterm in t that is equal to old_value with new_value. The replacements are performed in top down order. For example, replace(f(f(x)), f(x), x) returns f(x) and not x.

Parameters:

• t A term

• old_value The subterm that will be replaced.

• new_value The value that will be substituted.

Returns: The result of the replacement.

Functions¶

bottom_up_replace_aterm_builder<Builder, ReplaceFunction> atermpp::detail::make_bottom_up_replace_aterm_builder(ReplaceFunction f)
cached_bottom_up_replace_aterm_builder<Builder, ReplaceFunction> atermpp::detail::make_cached_bottom_up_replace_aterm_builder(ReplaceFunction f, std::unordered_map<aterm_appl, aterm> &cache)
partial_replace_aterm_builder<Builder, ReplaceFunction> atermpp::detail::make_partial_replace_aterm_builder(ReplaceFunction f)
replace_aterm_builder<Builder, ReplaceFunction> atermpp::detail::make_replace_aterm_builder(ReplaceFunction f)