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

Side by Side Diff: sdk/lib/collection/linked_list.dart

Issue 13459002: Introduce new LinkedList to dart:collection. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/collection/collection_sources.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of dart.collection;
6
7 class LinkedList
Lasse Reichstein Nielsen 2013/04/02 08:23:44 <E extends LinkedListEntry>
Anders Johnsen 2013/05/16 09:17:40 Done.
8 extends Collection<LinkedListEntry>
9 implements _LinkedListEntry {
10 int _length;
11 LinkedList _list;
12 _LinkedListEntry _next;
13 _LinkedListEntry _prev;
14
15 LinkedList() {
16 _next = _prev = _list = this;
Lasse Reichstein Nielsen 2013/04/02 08:23:44 No need for _list here.
Anders Johnsen 2013/05/16 09:17:40 Done.
17 }
18
19 void add(LinkedListEntry entry) {
Lasse Reichstein Nielsen 2013/04/02 08:23:44 (E entry)
Anders Johnsen 2013/05/16 09:17:40 Done.
20 _insertAfter(_prev, entry);
21 _length++;
Lasse Reichstein Nielsen 2013/04/02 08:23:44 void remove(E entry) { if (entry._list != this)
Anders Johnsen 2013/05/16 09:17:40 Done.
22 }
23
24 void _insertAfter(_LinkedListEntry entry, _LinkedListEntry newEntry) {
Lasse Reichstein Nielsen 2013/04/02 08:23:44 Last _LinkedListEntry -> E
Anders Johnsen 2013/05/16 09:17:40 Done.
25 newEntry._list = this;
Lasse Reichstein Nielsen 2013/04/02 08:23:44 assert(newEntry.list == null);
Anders Johnsen 2013/05/16 09:17:40 Done.
26 entry._next._prev = entry;
27 newEntry._prev = entry;
28 newEntry._next = entry._next;
29 entry._next = newEntry;
30 }
31
32 Iterator<LinkedListEntry> get iterator {
33 return new _LinkedListIterator(this);
34 }
35
36 int get length => _length;
37 }
38
39 class _LinkedListIterator implements Iterator<LinkedListEntry> {
Lasse Reichstein Nielsen 2013/04/02 08:23:44 _LinkedListIterator<E extends LinkedListEntry> imp
Anders Johnsen 2013/05/16 09:17:40 Done.
40 LinkedList _list;
41 _LinkedListEntry _current;
Lasse Reichstein Nielsen 2013/04/02 08:23:44 Consider having: E _current = null; _LinkedLis
Anders Johnsen 2013/05/16 09:17:40 Done.
42
43 _LinkedListIterator(this._list) {
44 _current = _list;
45 }
46
47 LinkedListEntry get current {
48 if (_current == _list) return null;
49 return _current;
50 }
51
52 bool moveNext() {
53 if (_current == null) return false;
54 if (_current._next == _list) return false;
Lasse Reichstein Nielsen 2013/04/02 08:23:44 if (identical(_current._next, _list) { _current
Anders Johnsen 2013/05/16 09:17:40 Done.
55 _current = _current._next;
56 return true;
57 }
58 }
59
60 class _LinkedListEntry {
61 LinkedList _list;
Lasse Reichstein Nielsen 2013/04/02 08:23:44 Move to LinkedListEntry
Anders Johnsen 2013/05/16 09:17:40 Done.
62 _LinkedListEntry _next;
63 _LinkedListEntry _prev;
64 }
65
66 abstract class LinkedListEntry extends _LinkedListEntry {
67 void unlink() {
68 _next.prev = _prev;
69 _prev.next = _next;
70 _list._length--;
71 _list = _next = _prev = null;
72 }
73
74 LinkedListEntry get next {
75 return _next;
76 }
77
78 LinkedListEntry get prev {
79 if (_prev == _list) return null;
80 return _prev;
81 }
Lasse Reichstein Nielsen 2013/04/02 08:23:44 Make a "list" getter, so you can go from an elemen
Anders Johnsen 2013/05/16 09:17:40 Done.
82 }
OLDNEW
« no previous file with comments | « sdk/lib/collection/collection_sources.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698