Git Product home page Git Product logo

dart_types's People

Contributors

osaxma avatar

Stargazers

 avatar

Watchers

 avatar

dart_types's Issues

The transitiveReduction algorithm is inaccurate and slow

Currently we generate the matrix as follow:

static Map<DartType, List<DartType>> _createTypeMatrix(
List<DartType> types,
TypeSystem typeSystem,
) {
logger.trace('_createTypeMatrix start (types length: ${types.length})');
final matrix = <DartType, List<DartType> /* subtypes */ >{};
for (var t in types) {
final edges = types
.where((element) => element != t && typeSystem.isSubtypeOf(element, t))
.toSet()
.toList();
matrix[t] = edges;
}
logger.trace('_createTypeMatrix end: (matrix length = ${matrix.length})');
return matrix;
}

Then we generate the transitive reduction of the graph as follow:

Map<T, Set<T>> transitiveReduction<T>(Map<T, Iterable<T>> graph) {
logger.trace('transitiveReduction start (graph length: ${graph.length})');
var result = <T, Set<T>>{};
graph.forEach((vertex, edges) {
result[vertex] = Set<T>.from(edges.where((element) => element != vertex));
});
// Lists are faster to iterate than maps, so we create a list since we're
// iterating repeatedly.
var keys = graph.keys.toList();
for (var vertex1 in keys) {
for (var vertex2 in keys) {
for (var vertex3 in keys) {
if (result[vertex1]!.contains(vertex2) && result[vertex2]!.contains(vertex3)) {
result[vertex1]!.remove(vertex3);
}
}
}
}
logger.trace('transitiveReduction end: (result length = ${result.length})');
return result;
}

The transitiveReduction has two issues:

  • It doesn't remove edges accurately when there are more than two edges in a path
    • e.g. A -> B -> C -> D; A -> C; A-> D -- it won't remove A->D here.
    • I think because we sort all the types by subtypes, we reduced this issue
  • It's slow! Running the all_types.dart example without selecting a type or applying filters, won't even complete on my machine before the laptop gets extremely hot and the fan gets quite noisy.

I think there should be a better way to generate the transitive reduction of the graph directly and more efficiently.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.