// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. import 'dart:collection'; import 'utils.dart'; /// A representation of a Graph since none is specified in `lib/`. class Graph { final Map?> _graph; Graph(this._graph); List edges(String node) => _graph[node] ?? []; Iterable get allNodes => _graph.keys; } class BadGraph { final Map?> _graph; BadGraph(Map?> values) : _graph = LinkedHashMap(equals: xEquals, hashCode: xHashCode) ..addEntries( values.entries .map((e) => MapEntry(X(e.key), e.value?.map(X.new).toList())), ); List edges(X node) => _graph[node] ?? []; Iterable get allNodes => _graph.keys; } /// A representation of a Graph where keys can asynchronously be resolved to /// real values or to edges. class AsyncGraph { final Map?> graph; AsyncGraph(this.graph); Future readNode(String node) async => graph.containsKey(node) ? node : null; Future> edges(String key, String? node) async => graph[key] ?? []; }