| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.utilities.collection; | 8 library engine.utilities.collection; |
| 9 | 9 |
| 10 import 'java_core.dart'; | 10 import 'java_core.dart'; |
| 11 import 'scanner.dart' show Token; | 11 import 'scanner.dart' show Token; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * The class `BooleanArray` defines methods for operating on integers as if they
were arrays | |
| 15 * of booleans. These arrays can be indexed by either integers or by enumeration
constants. | |
| 16 */ | |
| 17 class BooleanArray { | |
| 18 /** | |
| 19 * Return the value of the element at the given index. | |
| 20 * | |
| 21 * @param array the array being accessed | |
| 22 * @param index the index of the element being accessed | |
| 23 * @return the value of the element at the given index | |
| 24 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
| 25 */ | |
| 26 static bool get(int array, int index) { | |
| 27 _checkIndex(index); | |
| 28 return (array & (1 << index)) > 0; | |
| 29 } | |
| 30 | |
| 31 /** | |
| 32 * Return the value of the element at the given index. | |
| 33 * | |
| 34 * @param array the array being accessed | |
| 35 * @param index the index of the element being accessed | |
| 36 * @return the value of the element at the given index | |
| 37 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
| 38 */ | |
| 39 static bool getEnum(int array, Enum index) => get(array, index.ordinal); | |
| 40 | |
| 41 /** | |
| 42 * Set the value of the element at the given index to the given value. | |
| 43 * | |
| 44 * @param array the array being modified | |
| 45 * @param index the index of the element being set | |
| 46 * @param value the value to be assigned to the element | |
| 47 * @return the updated value of the array | |
| 48 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
| 49 */ | |
| 50 static int set(int array, int index, bool value) { | |
| 51 _checkIndex(index); | |
| 52 if (value) { | |
| 53 return array | (1 << index); | |
| 54 } else { | |
| 55 return array & ~(1 << index); | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 /** | |
| 60 * Set the value of the element at the given index to the given value. | |
| 61 * | |
| 62 * @param array the array being modified | |
| 63 * @param index the index of the element being set | |
| 64 * @param value the value to be assigned to the element | |
| 65 * @return the updated value of the array | |
| 66 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
| 67 */ | |
| 68 static int setEnum(int array, Enum index, bool value) => set(array, index.ordi
nal, value); | |
| 69 | |
| 70 /** | |
| 71 * Throw an exception if the index is not within the bounds allowed for an int
eger-encoded array | |
| 72 * of boolean values. | |
| 73 * | |
| 74 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
| 75 */ | |
| 76 static void _checkIndex(int index) { | |
| 77 if (index < 0 || index > 30) { | |
| 78 throw new RangeError("Index not between 0 and 30: ${index}"); | |
| 79 } | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 /** | |
| 84 * Instances of the class `TokenMap` map one set of tokens to another set of tok
ens. | |
| 85 */ | |
| 86 class TokenMap { | |
| 87 /** | |
| 88 * A table mapping tokens to tokens. This should be replaced by a more perform
ant implementation. | |
| 89 * One possibility is a pair of parallel arrays, with keys being sorted by the
ir offset and a | |
| 90 * cursor indicating where to start searching. | |
| 91 */ | |
| 92 Map<Token, Token> _map = new Map<Token, Token>(); | |
| 93 | |
| 94 /** | |
| 95 * Return the token that is mapped to the given token, or `null` if there is n
o token | |
| 96 * corresponding to the given token. | |
| 97 * | |
| 98 * @param key the token being mapped to another token | |
| 99 * @return the token that is mapped to the given token | |
| 100 */ | |
| 101 Token get(Token key) => _map[key]; | |
| 102 | |
| 103 /** | |
| 104 * Map the key to the value. | |
| 105 * | |
| 106 * @param key the token being mapped to the value | |
| 107 * @param value the token to which the key will be mapped | |
| 108 */ | |
| 109 void put(Token key, Token value) { | |
| 110 _map[key] = value; | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 /** | |
| 115 * Instances of the class `DirectedGraph` implement a directed graph in which th
e nodes are | 14 * Instances of the class `DirectedGraph` implement a directed graph in which th
e nodes are |
| 116 * arbitrary (client provided) objects and edges are represented implicitly. The
graph will allow an | 15 * arbitrary (client provided) objects and edges are represented implicitly. The
graph will allow an |
| 117 * edge from any node to any other node, including itself, but will not represen
t multiple edges | 16 * edge from any node to any other node, including itself, but will not represen
t multiple edges |
| 118 * between the same pair of nodes. | 17 * between the same pair of nodes. |
| 119 * | 18 * |
| 120 * @param N the type of the nodes in the graph | 19 * @param N the type of the nodes in the graph |
| 121 */ | 20 */ |
| 122 class DirectedGraph<N> { | 21 class DirectedGraph<N> { |
| 123 /** | 22 /** |
| 124 * The table encoding the edges in the graph. An edge is represented by an ent
ry mapping the head | 23 * The table encoding the edges in the graph. An edge is represented by an ent
ry mapping the head |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 w = _pop(); | 329 w = _pop(); |
| 431 component.add(w); | 330 component.add(w); |
| 432 _nodeMap[w].component = component; | 331 _nodeMap[w].component = component; |
| 433 } while (!identical(w, v)); | 332 } while (!identical(w, v)); |
| 434 } | 333 } |
| 435 return vInfo; | 334 return vInfo; |
| 436 } | 335 } |
| 437 } | 336 } |
| 438 | 337 |
| 439 /** | 338 /** |
| 339 * Instances of the class `TokenMap` map one set of tokens to another set of tok
ens. |
| 340 */ |
| 341 class TokenMap { |
| 342 /** |
| 343 * A table mapping tokens to tokens. This should be replaced by a more perform
ant implementation. |
| 344 * One possibility is a pair of parallel arrays, with keys being sorted by the
ir offset and a |
| 345 * cursor indicating where to start searching. |
| 346 */ |
| 347 Map<Token, Token> _map = new Map<Token, Token>(); |
| 348 |
| 349 /** |
| 350 * Return the token that is mapped to the given token, or `null` if there is n
o token |
| 351 * corresponding to the given token. |
| 352 * |
| 353 * @param key the token being mapped to another token |
| 354 * @return the token that is mapped to the given token |
| 355 */ |
| 356 Token get(Token key) => _map[key]; |
| 357 |
| 358 /** |
| 359 * Map the key to the value. |
| 360 * |
| 361 * @param key the token being mapped to the value |
| 362 * @param value the token to which the key will be mapped |
| 363 */ |
| 364 void put(Token key, Token value) { |
| 365 _map[key] = value; |
| 366 } |
| 367 } |
| 368 |
| 369 /** |
| 440 * The interface `MapIterator` defines the behavior of objects that iterate over
the entries | 370 * The interface `MapIterator` defines the behavior of objects that iterate over
the entries |
| 441 * in a map. | 371 * in a map. |
| 442 * | 372 * |
| 443 * This interface defines the concept of a current entry and provides methods to
access the key and | 373 * This interface defines the concept of a current entry and provides methods to
access the key and |
| 444 * value in the current entry. When an iterator is first created it will be posi
tioned before the | 374 * value in the current entry. When an iterator is first created it will be posi
tioned before the |
| 445 * first entry and there is no current entry until [moveNext] is invoked. When a
ll of the | 375 * first entry and there is no current entry until [moveNext] is invoked. When a
ll of the |
| 446 * entries have been accessed there will also be no current entry. | 376 * entries have been accessed there will also be no current entry. |
| 447 * | 377 * |
| 448 * There is no guarantee made about the order in which the entries are accessibl
e. | 378 * There is no guarantee made about the order in which the entries are accessibl
e. |
| 449 */ | 379 */ |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 _currentIterator = iterator; | 526 _currentIterator = iterator; |
| 597 return true; | 527 return true; |
| 598 } | 528 } |
| 599 _iteratorIndex++; | 529 _iteratorIndex++; |
| 600 } | 530 } |
| 601 return false; | 531 return false; |
| 602 } | 532 } |
| 603 } | 533 } |
| 604 | 534 |
| 605 /** | 535 /** |
| 536 * The class `BooleanArray` defines methods for operating on integers as if they
were arrays |
| 537 * of booleans. These arrays can be indexed by either integers or by enumeration
constants. |
| 538 */ |
| 539 class BooleanArray { |
| 540 /** |
| 541 * Return the value of the element at the given index. |
| 542 * |
| 543 * @param array the array being accessed |
| 544 * @param index the index of the element being accessed |
| 545 * @return the value of the element at the given index |
| 546 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive |
| 547 */ |
| 548 static bool get(int array, int index) { |
| 549 _checkIndex(index); |
| 550 return (array & (1 << index)) > 0; |
| 551 } |
| 552 |
| 553 /** |
| 554 * Return the value of the element at the given index. |
| 555 * |
| 556 * @param array the array being accessed |
| 557 * @param index the index of the element being accessed |
| 558 * @return the value of the element at the given index |
| 559 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive |
| 560 */ |
| 561 static bool getEnum(int array, Enum index) => get(array, index.ordinal); |
| 562 |
| 563 /** |
| 564 * Set the value of the element at the given index to the given value. |
| 565 * |
| 566 * @param array the array being modified |
| 567 * @param index the index of the element being set |
| 568 * @param value the value to be assigned to the element |
| 569 * @return the updated value of the array |
| 570 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive |
| 571 */ |
| 572 static int set(int array, int index, bool value) { |
| 573 _checkIndex(index); |
| 574 if (value) { |
| 575 return array | (1 << index); |
| 576 } else { |
| 577 return array & ~(1 << index); |
| 578 } |
| 579 } |
| 580 |
| 581 /** |
| 582 * Set the value of the element at the given index to the given value. |
| 583 * |
| 584 * @param array the array being modified |
| 585 * @param index the index of the element being set |
| 586 * @param value the value to be assigned to the element |
| 587 * @return the updated value of the array |
| 588 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive |
| 589 */ |
| 590 static int setEnum(int array, Enum index, bool value) => set(array, index.ordi
nal, value); |
| 591 |
| 592 /** |
| 593 * Throw an exception if the index is not within the bounds allowed for an int
eger-encoded array |
| 594 * of boolean values. |
| 595 * |
| 596 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive |
| 597 */ |
| 598 static void _checkIndex(int index) { |
| 599 if (index < 0 || index > 30) { |
| 600 throw new RangeError("Index not between 0 and 30: ${index}"); |
| 601 } |
| 602 } |
| 603 } |
| 604 |
| 605 /** |
| 606 * Instances of the class `SingleMapIterator` implement an iterator that can be
used to access | 606 * Instances of the class `SingleMapIterator` implement an iterator that can be
used to access |
| 607 * the entries in a single map. | 607 * the entries in a single map. |
| 608 */ | 608 */ |
| 609 class SingleMapIterator<K, V> implements MapIterator<K, V> { | 609 class SingleMapIterator<K, V> implements MapIterator<K, V> { |
| 610 /** | 610 /** |
| 611 * Returns a new [SingleMapIterator] instance for the given [Map]. | 611 * Returns a new [SingleMapIterator] instance for the given [Map]. |
| 612 */ | 612 */ |
| 613 static SingleMapIterator forMap(Map map) => new SingleMapIterator(map); | 613 static SingleMapIterator forMap(Map map) => new SingleMapIterator(map); |
| 614 | 614 |
| 615 /** | 615 /** |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 | 671 |
| 672 @override | 672 @override |
| 673 void set value(V newValue) { | 673 void set value(V newValue) { |
| 674 if (_currentKey == null) { | 674 if (_currentKey == null) { |
| 675 throw new NoSuchElementException(); | 675 throw new NoSuchElementException(); |
| 676 } | 676 } |
| 677 _currentValue = newValue; | 677 _currentValue = newValue; |
| 678 _map[_currentKey] = newValue; | 678 _map[_currentKey] = newValue; |
| 679 } | 679 } |
| 680 } | 680 } |
| OLD | NEW |