| Package | as3.collections |
| Class | public class SortedMap |
| Implements | ISortedMap |
| Subclasses | SortedMapFx |
The SortedMap uses a treap to achieve the sorting and a map in order to a fast key look-up.
An exception will be thrown for any trial to add a key, that does not match with the type of the internal TypedDictionary instance. In other words, adding keys of a consistent type will not cause any exception. See the head section of the TypedDictionary for more information.
Trying to add an item that is not comparable due to a type mismatch will throw another execption. See the Treap documentation.
Runtime of operationsSee also
| Property | Defined by | ||
|---|---|---|---|
| numItems : uint [read-only]
Returns the size of the collection.
| SortedMap | ||
| Property | Defined by | ||
|---|---|---|---|
| _map : IMap
The internal map.
| SortedMap | ||
| _treap : ISortedSet
The search tree.
| SortedMap | ||
| Method | Defined by | ||
|---|---|---|---|
|
SortedMap(comparator:IComparator)
Creates a new SortedMap instance.
| SortedMap | ||
|
addItem(key:*, item:*):Boolean
Adds a new item to the map.
| SortedMap | ||
|
clear():void
Removes all items from the collection.
| SortedMap | ||
|
getEqualItemKey(item:*):*
Returns the key of the item, that is equal to the given item against the sort criterion.
| SortedMap | ||
|
getFirstItem():*
Returns the lowest item of the sorted map.
| SortedMap | ||
|
getItem(key:*):*
Returns the item associated with the given key.
| SortedMap | ||
|
getIterator(cursor:uint = 0):IIterator
Returns an iterator over the map items starting at the specified position.
| SortedMap | ||
|
getKeyIterator(cursor:uint = 0):IIterator
Returns an iterator over the map keys starting at the specified position.
| SortedMap | ||
|
getLastItem():*
Returns the greatest item of the sorted map.
| SortedMap | ||
|
getMapIterator(cursor:uint = 0):IMapIterator
Returns a map iterator, which provides additionally access to the key of
the last returned item.
| SortedMap | ||
|
hasEqualItem(item:*):Boolean
Returns true, if the map contains at least one item that is equal
to the given item against the sort criterion.
| SortedMap | ||
|
hasKey(key:*):Boolean
Tests, if the map contains an item for the given key.
| SortedMap | ||
|
keysToArray():Array
Returns an array of all keys.
| SortedMap | ||
|
removeFirstItem():*
Removes the lowest item of the sorted map.
| SortedMap | ||
|
removeKey(key:*):*
Removes the key and the item associated with that key.
| SortedMap | ||
|
removeLastItem():*
Removes the greatest item of the sorted map.
| SortedMap | ||
|
replaceItem(key:*, item:*):Boolean
Replaces the item associated with the given key.
| SortedMap | ||
|
toArray():Array
Returns an array of all items in the order of the particular collection.
| SortedMap | ||
|
toString():String
Info
| SortedMap | ||
| Method | Defined by | ||
|---|---|---|---|
|
Template method to notify subclasses after a new node has been added.
| SortedMap | ||
|
nodeRemoved():void
Commits the removal of the node, announced in willRemoveNode()
| SortedMap | ||
|
updateItem(key:*, item:*):Boolean
Replaces the item associated with the given key.
| SortedMap | ||
|
willRemoveNode(node:MapEntry):void
Template method to notify subclasses when a node is about to be removed.
| SortedMap | ||
| _map | property |
protected var _map:IMapThe internal map.
| numItems | property |
numItems:uint [read-only]Returns the size of the collection.
Implementation public function get numItems():uint
| _treap | property |
protected var _treap:ISortedSetThe search tree.
| SortedMap | () | constructor |
public function SortedMap(comparator:IComparator)Creates a new SortedMap instance.
Parameterscomparator:IComparator — The sort criterion.
|
| addItem | () | method |
public function addItem(key:*, item:*):BooleanAdds a new item to the map.
If the key already exists, the item associated with that key will be replaced, unless they are equal.
Parameterskey:* — The key.
|
|
item:* — The item to be added.
|
Boolean — true, if the item has been added or replaced.
|
UnsupportedTypeException — If the key type does not match
with the type of the internal map.
|
|
UnsupportedTypeException — If the item cannot be compared.
|
| clear | () | method |
public function clear():voidRemoves all items from the collection.
| getEqualItemKey | () | method |
public function getEqualItemKey(item:*):*Returns the key of the item, that is equal to the given item against the sort criterion.
Parametersitem:* — The item to test.
|
* — The equal item, if any, or undefined.
|
| getFirstItem | () | method |
public function getFirstItem():*Returns the lowest item of the sorted map.
Returns* — The first item or undefined, if the map is empty.
|
| getItem | () | method |
public function getItem(key:*):*Returns the item associated with the given key.
Parameterskey:* — The key.
|
* — The item, if the key exists, else undefined.
|
| getIterator | () | method |
public function getIterator(cursor:uint = 0):IIteratorReturns an iterator over the map items starting at the specified position.
A MapIterator instance is returned here.
Parameterscursor:uint (default = 0) — Start position of the enumeration.
|
IIterator —
The iterator.
|
See also
| getKeyIterator | () | method |
public function getKeyIterator(cursor:uint = 0):IIteratorReturns an iterator over the map keys starting at the specified position.
Returns a wrapper of the iterator of the internal treap. Order and cost for instantiation and cursor positioning may be found there.
Parameterscursor:uint (default = 0) — Start position of the enumeration.
|
IIterator —
The key iterator.
|
See also
| getLastItem | () | method |
public function getLastItem():*Returns the greatest item of the sorted map.
Returns* — The last item or undefined, if the map is empty.
|
| getMapIterator | () | method |
public function getMapIterator(cursor:uint = 0):IMapIteratorReturns a map iterator, which provides additionally access to the key of the last returned item.
Since the MapIterator utilises the key iterator of the particular map, expected order and the costs of instantiation and cursor initialisation are the same as for the key iterator.
Parameterscursor:uint (default = 0) — Start position of the iterator.
|
IMapIterator —
The map iterator.
|
| hasEqualItem | () | method |
public function hasEqualItem(item:*):BooleanReturns true, if the map contains at least one item that is equal to the given item against the sort criterion.
Parametersitem:* — The item to test.
|
Boolean — true, if there are equal items, else false.
|
| hasKey | () | method |
public function hasKey(key:*):BooleanTests, if the map contains an item for the given key.
Parameterskey:* — The key to test.
|
Boolean — true, if an item for that key is stored, else false.
|
| keysToArray | () | method |
public function keysToArray():ArrayReturns an array of all keys.
There is basically no assumption of the order of the keys.
ReturnsArray |
| nodeAdded | () | method |
protected function nodeAdded(node:MapEntry):voidTemplate method to notify subclasses after a new node has been added.
Parametersnode:MapEntry — The last added node.
|
| nodeRemoved | () | method |
protected function nodeRemoved():voidCommits the removal of the node, announced in willRemoveNode()
| removeFirstItem | () | method |
public function removeFirstItem():*Removes the lowest item of the sorted map.
Returns* — The first item or undefined, if the map is empty.
|
| removeKey | () | method |
public function removeKey(key:*):*Removes the key and the item associated with that key.
Parameterskey:* — The key.
|
* — The item, if the key exists, else undefined.
|
| removeLastItem | () | method |
public function removeLastItem():*Removes the greatest item of the sorted map.
Returns* — The last item or undefined, if the map is empty.
|
| replaceItem | () | method |
public function replaceItem(key:*, item:*):BooleanReplaces the item associated with the given key.
An item won't be replaced, if the key does not exist in the map or if the currently for that key stored item equals the given item.
Parameterskey:* — The key.
|
|
item:* — The replacing item.
|
Boolean — true, if the item has been replaced.
|
| toArray | () | method |
public function toArray():ArrayReturns an array of all items in the order of the particular collection.
ReturnsArray — The array.
|
| toString | () | method |
public function toString():StringInfo
ReturnsString |
| updateItem | () | method |
protected function updateItem(key:*, item:*):BooleanReplaces the item associated with the given key.
If the new value has an equal in the treap, the item will not be added, even if the new value equals the old value.
Parameterskey:* — The key.
|
|
item:* — The replacing item.
|
Boolean — true, if the item has been replaced and false, if the same item
or an equal item already exists for that key.
|
UnsupportedTypeException — If the item cannot be compared.
|
| willRemoveNode | () | method |
protected function willRemoveNode(node:MapEntry):voidTemplate method to notify subclasses when a node is about to be removed.
We need this node to create a reference to its predecessor. After the node has been removed, this reference would be null. The subclass is in charge to cache the node's predecessor till the node is finally removed.
Parametersnode:MapEntry — The node that will be removed soon.
|