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

Side by Side Diff: pkg/mdv/lib/src/list_diff.dart

Issue 20149004: [mdv] implement Node.createBinding and Node.createBindings (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library mdv.src.list_diff; 5 library mdv.src.list_diff;
6 6
7 import 'dart:math' as math; 7 import 'dart:math' as math;
8 import 'package:observe/observe.dart' show ListChangeRecord; 8 import 'package:observe/observe.dart' show ListChangeRecord;
9 9
10 /** 10 /**
(...skipping 20 matching lines...) Expand all
31 31
32 // TODO(jmesserly): freeze remove list before handing it out? 32 // TODO(jmesserly): freeze remove list before handing it out?
33 /** The items removed, if any. Otherwise this will be an empty list. */ 33 /** The items removed, if any. Otherwise this will be an empty list. */
34 List get removed => _removed; 34 List get removed => _removed;
35 35
36 /** The number of items added. */ 36 /** The number of items added. */
37 int get addedCount => _addedCount; 37 int get addedCount => _addedCount;
38 38
39 int get removedCount => _removed.length; 39 int get removedCount => _removed.length;
40 40
41 /** Returns true if the provided index was changed by this operation. */
42 bool changes(key) {
43 // If key isn't an int, or before the index, then it wasn't changed.
44 if (key is! int || key < index) return false;
45
46 // If this was a shift operation, anything after index is changed.
47 if (addedCount != removedCount) return true;
48
49 // Otherwise, anything in the update range was changed.
50 return key < index + addedCount;
51 }
52
41 String toString() => '#<$runtimeType index: $index, ' 53 String toString() => '#<$runtimeType index: $index, '
42 'removed: $removed, addedCount: $addedCount>'; 54 'removed: $removed, addedCount: $addedCount>';
43 } 55 }
44 56
45 // Note: This function is *based* on the computation of the Levenshtein 57 // Note: This function is *based* on the computation of the Levenshtein
46 // "edit" distance. The one change is that "updates" are treated as two 58 // "edit" distance. The one change is that "updates" are treated as two
47 // edits - not one. With List splices, an update is really a delete 59 // edits - not one. With List splices, an update is really a delete
48 // followed by an add. By retaining this, we optimize for "keeping" the 60 // followed by an add. By retaining this, we optimize for "keeping" the
49 // maximum array items in the original array. For example: 61 // maximum array items in the original array. For example:
50 // 62 //
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 oldIndex++; 259 oldIndex++;
248 break; 260 break;
249 } 261 }
250 } 262 }
251 263
252 if (splice != null) { 264 if (splice != null) {
253 splices.add(splice); 265 splices.add(splice);
254 } 266 }
255 return splices; 267 return splices;
256 } 268 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698