Packageas3.collections
Classpublic class SortedMap
ImplementsISortedMap
SubclassesSortedMapFx

Map, whose items are kept in a sorted order defined by a comparator.

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 operations (ignores Flash Dictionary runtime)

See also

as3.collections.core.Treap
as3.collections.core.TypedDictionary


Public Properties
 PropertyDefined by
  numItems : uint
[read-only] Returns the size of the collection.
SortedMap
Protected Properties
 PropertyDefined by
  _map : IMap
The internal map.
SortedMap
  _treap : ISortedSet
The search tree.
SortedMap
Public Methods
 MethodDefined 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
  
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
  
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
  
Removes the lowest item of the sorted map.
SortedMap
  
removeKey(key:*):*
Removes the key and the item associated with that key.
SortedMap
  
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
Protected Methods
 MethodDefined by
  
nodeAdded(node:MapEntry):void
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
  
Template method to notify subclasses when a node is about to be removed.
SortedMap
Property detail
_mapproperty
protected var _map:IMap

The internal map.

numItemsproperty 
numItems:uint  [read-only]

Returns the size of the collection.

Implementation
    public function get numItems():uint
_treapproperty 
protected var _treap:ISortedSet

The search tree.

Constructor detail
SortedMap()constructor
public function SortedMap(comparator:IComparator)

Creates a new SortedMap instance.

Parameters
comparator:IComparator — The sort criterion.
Method detail
addItem()method
public function addItem(key:*, item:*):Boolean

Adds a new item to the map.

If the key already exists, the item associated with that key will be replaced, unless they are equal.

Parameters
key:* — The key.
 
item:* — The item to be added.

Returns
Boolean — true, if the item has been added or replaced.

Throws
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():void

Removes 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.

Parameters
item:* — The item to test.

Returns
* — 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.

Parameters
key:* — The key.

Returns
* — The item, if the key exists, else undefined.
getIterator()method 
public function getIterator(cursor:uint = 0):IIterator

Returns an iterator over the map items starting at the specified position.

A MapIterator instance is returned here.

Parameters
cursor:uint (default = 0) — Start position of the enumeration.

Returns
IIterator — The iterator.

See also

getKeyIterator()method 
public function getKeyIterator(cursor:uint = 0):IIterator

Returns 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.

Parameters
cursor:uint (default = 0) — Start position of the enumeration.

Returns
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):IMapIterator

Returns 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.

Parameters
cursor:uint (default = 0) — Start position of the iterator.

Returns
IMapIterator — The map iterator.
hasEqualItem()method 
public function hasEqualItem(item:*):Boolean

Returns true, if the map contains at least one item that is equal to the given item against the sort criterion.

Parameters
item:* — The item to test.

Returns
Boolean — true, if there are equal items, else false.
hasKey()method 
public function hasKey(key:*):Boolean

Tests, if the map contains an item for the given key.

Parameters
key:* — The key to test.

Returns
Boolean — true, if an item for that key is stored, else false.
keysToArray()method 
public function keysToArray():Array

Returns an array of all keys.

There is basically no assumption of the order of the keys.

Returns
Array
nodeAdded()method 
protected function nodeAdded(node:MapEntry):void

Template method to notify subclasses after a new node has been added.

Parameters
node:MapEntry — The last added node.
nodeRemoved()method 
protected function nodeRemoved():void

Commits 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.

Parameters
key:* — The key.

Returns
* — 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:*):Boolean

Replaces 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.

Parameters
key:* — The key.
 
item:* — The replacing item.

Returns
Boolean — true, if the item has been replaced.
toArray()method 
public function toArray():Array

Returns an array of all items in the order of the particular collection.

Returns
Array — The array.
toString()method 
public function toString():String

Info

Returns
String
updateItem()method 
protected function updateItem(key:*, item:*):Boolean

Replaces 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.

Parameters
key:* — The key.
 
item:* — The replacing item.

Returns
Boolean — true, if the item has been replaced and false, if the same item or an equal item already exists for that key.

Throws
UnsupportedTypeException — If the item cannot be compared.
willRemoveNode()method 
protected function willRemoveNode(node:MapEntry):void

Template 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.

Parameters
node:MapEntry — The node that will be removed soon.