Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2224)

Unified Diff: lib/src/util/iterable_set.dart

Issue 1887853002: Add a LiveSuite class. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/runner/live_suite_controller.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/util/iterable_set.dart
diff --git a/lib/src/util/iterable_set.dart b/lib/src/util/iterable_set.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5166a725a0a8253db399ca6afb1f6375f093b688
--- /dev/null
+++ b/lib/src/util/iterable_set.dart
@@ -0,0 +1,35 @@
+// Copyright (c) 2016, 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 'package:collection/collection.dart';
+
+/// An unmodifiable [Set] view backed by an arbitrary [Iterable].
+///
+/// Note that contrary to most APIs that take iterables, this does not convert
+/// its argument to another collection before use. This means that if it's
+/// lazily-generated, that generation will happen for every operation.
+///
+/// Note also that set operations that are usually expected to be `O(1)` or
+/// `O(log(n))`, such as [contains], may be `O(n)` for many underlying iterable
+/// types. As such, this should only be used for small iterables.
+class IterableSet<E> extends SetMixin<E> with UnmodifiableSetMixin<E> {
+ /// The base iterable that set operations forward to.
+ final Iterable<E> _base;
+
+ int get length => _base.length;
+
+ Iterator<E> get iterator => _base.iterator;
+
+ /// Creates a [Set] view of [base].
+ IterableSet(this._base);
+
+ bool contains(Object element) => _base.contains(element);
+
+ E lookup(Object needle) =>
+ _base.firstWhere((element) => element == needle, orElse: () => null);
+
+ Set<E> toSet() => _base.toSet();
+}
« no previous file with comments | « lib/src/runner/live_suite_controller.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698