Packageas3.collections
Classpublic class LinkedMap
InheritanceLinkedMap Inheritance AbstractLinkedList
ImplementsILinkedMap
SubclassesLinkedMapFx

Map made up of sequentially linked objects.

The LinkedMap is a specialisation of the AbstractLinkedList, from that it inherits all functionality, that makes up the linked structure. Additionally, the LinkedMap holds an internal map instance 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.

The class defines methods in a custom namespace (as3_collections), which enables safe framework internal access to non public methods.

Runtime of operations (ignores Flash Dictionary runtime)

See also

as3.collections.core.AbstractLinkedList
as3.collections.core.TypedDictionary


Public Properties
 PropertyDefined by
 InheritednumItems : uint
Returns the size of the linked list.
AbstractLinkedList
Protected Properties
 PropertyDefined by
 Inherited_first : LinkedNode
The first item of the linked list.
AbstractLinkedList
 Inherited_last : LinkedNode
The last item of the linked list.
AbstractLinkedList
  _map : IMap
The internal map.
LinkedMap
 Inherited_numItems : uint = 0
The size of the sequence.
AbstractLinkedList
 Inherited_pointer : AbstractPointer
The singleton linked list pointer.
AbstractLinkedList
Public Methods
 MethodDefined by
  
Creates a new LinkedMap instance.
LinkedMap
  
addItem(key:*, item:*):Boolean
Adds a new item to the map.
LinkedMap
  
addItemAtEnd(key:*, item:*):Boolean
Adds an item at the end of the linked map.
LinkedMap
  
addItemAtStart(key:*, item:*):Boolean
Adds an item in front of the linked map.
LinkedMap
  
clear():void
Clears the list by removing the references to the first and last item.
LinkedMap
 Inherited
Returns the first item of the linked list.
AbstractLinkedList
  
getItem(key:*):*
Returns the item associated with the given key.
LinkedMap
  
getIterator(cursor:uint = 0):IIterator
Returns an iterator starting at the specified position.
LinkedMap
  
getKeyIterator(cursor:uint = 0):IIterator
Returns an iterator over the map keys starting at the specified position.
LinkedMap
 Inherited
Returns the last item of the linked list.
AbstractLinkedList
  
getMapIterator(cursor:uint = 0):IMapIterator
Returns a map iterator, which provides additionally access to the key of the last returned item.
LinkedMap
  
Returns a map pointer for the linked map.
LinkedMap
  
hasKey(key:*):Boolean
Tests, if the map contains an item for the given key.
LinkedMap
  
keysToArray():Array
Returns an array of all keys.
LinkedMap
  
Removes the first item of the linked map.
LinkedMap
  
removeKey(key:*):*
Removes the key and the item associated with that key.
LinkedMap
  
Removes the last item of the linked map.
LinkedMap
  
replaceItem(key:*, item:*):Boolean
Replaces the item associated with the given key.
LinkedMap
 Inherited
reverse():void
Reverses the linked list order.
AbstractLinkedList
 Inherited
sort(comparator:IComparator):void
Sorts the linked list by a given criterion.
AbstractLinkedList
 Inherited
toArray():Array
Returns an array of all items in the present order.
AbstractLinkedList
  
toString():String
Info
LinkedMap
Protected Methods
 MethodDefined by
 Inherited
Adds the first node to an empty list.
AbstractLinkedList
 Inherited
Inserts a new node after an existing one.
AbstractLinkedList
 Inherited
Inserts a new node at the end of the sequence.
AbstractLinkedList
 Inherited
Inserts a new node at the start of the sequence.
AbstractLinkedList
 Inherited
Inserts a new node before an existing one.
AbstractLinkedList
  
Deregisters a node from the internal map.
LinkedMap
 Inherited
getNodeAt(index:uint):LinkedNode
Returns the node at a specific position.
AbstractLinkedList
 Inherited
insertionSort(comparator:IComparator):void
Insertion sort algorithm.
AbstractLinkedList
 Inherited
mergeSort(comparator:IComparator):void
Merge sort algorithm.
AbstractLinkedList
  
nodeAdded(node:LinkedNode):void
Template method to notify subclasses after a new node has been added.
LinkedMap
  
nodeRemoved():void
Commits the removal of the node, announced in willRemoveNode()
LinkedMap
  
Template method to notify subclasses after a node has been replaced.
LinkedMap
  
Registers a node in the internal map.
LinkedMap
 Inherited
Unlinks the first node of the sequence.
AbstractLinkedList
 Inherited
Unlinks the last node of the sequence.
AbstractLinkedList
 Inherited
Unlinks a node and connects predecessor with successor.
AbstractLinkedList
  
Template method to notify subclasses when a node is about to be removed.
LinkedMap
Property detail
_mapproperty
protected var _map:IMap

The internal map.

Constructor detail
LinkedMap()constructor
public function LinkedMap()

Creates a new LinkedMap instance.

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.
addItemAfterNode_internal()method 
as3_collections function addItemAfterNode_internal(leftNode:LinkedMapNode, key:*, item:*):Boolean

Framework internal method to add an item after an existing node.

Parameters
leftNode:LinkedMapNode — The existing node.
 
key:* — The key for the item to add.
 
item:* — The item to be added after the item of the existing node.

Returns
Boolean — true, if the node has been added and false, if the key already exists.

Throws
UnsupportedTypeException — If the key type does not match with the type of the internal map.
 
— If no left node is given, but the list is not empty. Developer error, should not appear.
addItemAtEnd()method 
public function addItemAtEnd(key:*, item:*):Boolean

Adds an item at the end of the linked map.

If the key already exists, the map will stay untouched and the method returns false.

Parameters
key:* — The key.
 
item:* — The item to be added at the end.

Returns
Boolean — true, if the item has been added or false, if the key already exists.

Throws
UnsupportedTypeException — If the key type does not match with the type of the internal map.
addItemAtStart()method 
public function addItemAtStart(key:*, item:*):Boolean

Adds an item in front of the linked map.

If the key already exists, the map will stay untouched and the method returns false.

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

Returns
Boolean — true, if the item has been added or false, if the key already exists.

Throws
UnsupportedTypeException — If the key type does not match with the type of the internal map.
addItemBeforeNode_internal()method 
as3_collections function addItemBeforeNode_internal(rightNode:LinkedMapNode, key:*, item:*):Boolean

as3_collections

Parameters
rightNode:LinkedMapNode
 
key:*
 
item:*

Returns
Boolean
clear()method 
public override function clear():void

Clears the list by removing the references to the first and last item. Cleans also the pointer reference.

May be extended in sub classes.

deregisterNode()method 
protected function deregisterNode(node:LinkedNode):void

Deregisters a node from the internal map.

Parameters
node:LinkedNode — The node to deregister.
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 override function getIterator(cursor:uint = 0):IIterator

Returns an iterator starting at the specified position.

Creates the iterator in constant time. Advancing the iterator to the specified position then takes linear time.

Returns the items in the order of the linked collection.

May be overridden in sub classes.

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

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.

Costs and order the same as for the iterator.

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

Returns
IIterator — The key iterator.

See also

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.
getPointer()method 
public function getPointer(key:*):IMapPointer

Returns a map pointer for the linked map.

Parameters
key:* — The key for the item, the pointer should point to initially (optional).

Returns
IMapPointer — The map pointer to modify the linked map.
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:LinkedNode):void

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

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

Commits the removal of the node, announced in willRemoveNode()

nodeReplaced()method 
protected function nodeReplaced(node:LinkedNode):void

Template method to notify subclasses after a node has been replaced.

Parameters
node:LinkedNode — The replaced node.
registerNode()method 
protected function registerNode(node:LinkedNode):void

Registers a node in the internal map.

Parameters
node:LinkedNode — The node to register.

Throws
UnsupportedTypeException — If the key type does not match with the type of the internal map.
removeFirstItem()method 
public function removeFirstItem():*

Removes the first item of the linked 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 last item of the linked map.

Returns
* — The last item or undefined, if the map is empty.
removeNode_internal()method 
as3_collections function removeNode_internal(node:LinkedMapNode):Boolean

Framework internal method to remove a node.

The method may be called with a null valued node.

Parameters
node:LinkedMapNode — The node to remove.

Returns
Boolean — true, if the node has been removed or false, if the given node is null.
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.
toString()method 
public function toString():String

Info

Returns
String
willRemoveNode()method 
protected function willRemoveNode(node:LinkedNode):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:LinkedNode — The node that will be removed soon.