Skip to content

Commit

Permalink
Improve performance of encodeNestedLists (#453)
Browse files Browse the repository at this point in the history
## Changes
* Closes #46.
* Improve performance of `encodeNestedLists` inside `setSubstitutionSystem$cpp.m` by not using `ReplaceRepeated`.

## Examples
```wl
In[]:= rules = {{{a_, b_}, {a_, c_}, {a_, d_}} :> 
    Module[{$0, $1, $2}, {{$0, $1}, {$1, $2}, {$2, $0}, {$0, $2}, \
{$2, $1}, {$1, $0}, {$0, b}, {$1, c}, {$2, d}, {b, $2}, {d, $0}}]};
AbsoluteTiming[set = SetReplace[{{0, 0}, {0, 0}, {0, 0}}, rules, 100]] // First
AbsoluteTiming[SetReplace[set, rules]][[1]]

Out[]= 0.052426
Out[]= 0.026598
```

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/maxitg/setreplace/453)
<!-- Reviewable:end -->
  • Loading branch information
daneelsan authored Oct 12, 2020
1 parent 2278ed1 commit e3192ed
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Kernel/setSubstitutionSystem$cpp.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
sublists. *)
(* This format is used to pass both rules and set data into libSetReplace over LibraryLink *)

encodeNestedLists[list_List] :=
{list} //. {{l___, List[args___], r___} :> {l, Length[{args}], args, r}}
encodeNestedLists[list_List] := Flatten @ {Length @ list, encodeNestedLists /@ list}
encodeNestedLists[arg_] := arg

(* This is the reverse, used to decode set data (a list of expressions) from libSetReplace *)

Expand Down

0 comments on commit e3192ed

Please sign in to comment.