Commit Graph

12 Commits

Author SHA1 Message Date
Sergey Elantsev 1ad01debf3 tiny optimisations of dag.Set
1. Use hint for map size in Set.Copy().
2. Use Set.Copy() if Set.Difference() argument is empty.
2021-04-09 22:59:30 +03:00
Dennis Gursky 550de86135
Set Intersection #performance (#28183)
* Set Intersection #performance

Intersection is faster for sets of different sizes if one iterates over the shorter set and checks the presence of an element in a larger one. For an edge case consider `s` having 1M entries and `other` no entries at all. In this case original code will iterate over 1M entries in `s` not finding anything and then returning an empty result set. In the patched code the iteration won't happen at all and result is returned immediately.

This change is inspired by profiling a relatively large terraform configuration, where the time to validate was sped up 4x with this change.
2021-03-24 13:04:37 -04:00
James Bardin 8925d94387 dag: staticcheck 2020-12-02 13:59:19 -05:00
James Bardin 268959f4be make UpEdges and DownEdges return a copy
The public functions for the graph UpEdges and DownEdges is returning
the internal Set from the graph, meaning that callers could
inadvertently corrupt the graph structure by editing the returned Sets.

Make UpEdges and DownEdges return a copy of the set, while retaining the
efficient no-copy behavior for internal callers.
2020-06-11 09:53:09 -04:00
James Bardin 32ae3b5452 make dag.Set a simple map
This allows iteration directly over the set, removing the need to
allocate and copy a new slice for every iteration.
2020-02-19 14:46:35 -05:00
Martin Atkins b28fc1cd20 dag: method for filtering a set on arbitrary criteria 2017-05-11 11:57:46 -07:00
Mitchell Hashimoto 77c445a838
dag: Set difference 2017-02-03 21:18:33 +01:00
Mitchell Hashimoto 05794199af dag: use hashcodes to as map key to edge sets 2015-10-27 11:58:34 -07:00
Mitchell Hashimoto ed2075e384 dag: TransitiveReduction 2015-02-27 19:12:19 -08:00
Mitchell Hashimoto 5c2639bd10 dag: export more things 2015-02-19 12:08:07 -08:00
Mitchell Hashimoto 9dfce9c93a dag: Remove, RemoveEdge, DownEdges, UpEdges 2015-02-19 12:07:54 -08:00
Mitchell Hashimoto 2a910585a2 dag: new Graph API 2015-02-19 12:07:51 -08:00