| Package | as3.collections |
| Class | public class LinkedMap |
| Inheritance | LinkedMap AbstractLinkedList |
| Implements | ILinkedMap |
| Subclasses | LinkedMapFx |
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 operationsSee also
| Property | Defined by | ||
|---|---|---|---|
![]() | _first : LinkedNode
The first item of the linked list.
| AbstractLinkedList | |
![]() | _last : LinkedNode
The last item of the linked list.
| AbstractLinkedList | |
| _map : IMap
The internal map.
| LinkedMap | ||
![]() | _numItems : uint = 0
The size of the sequence.
| AbstractLinkedList | |
![]() | _pointer : AbstractPointer
The singleton linked list pointer.
| AbstractLinkedList | |
| Method | Defined 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 | ||
![]() |
getFirstItem():*
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 | ||
![]() |
getLastItem():*
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 | ||
|
getPointer(key:*):IMapPointer
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 | ||
|
removeFirstItem():*
Removes the first item of the linked map.
| LinkedMap | ||
|
removeKey(key:*):*
Removes the key and the item associated with that key.
| LinkedMap | ||
|
removeLastItem():*
Removes the last item of the linked map.
| LinkedMap | ||
|
replaceItem(key:*, item:*):Boolean
Replaces the item associated with the given key.
| LinkedMap | ||
![]() |
reverse():void
Reverses the linked list order.
| AbstractLinkedList | |
![]() |
sort(comparator:IComparator):void
Sorts the linked list by a given criterion.
| AbstractLinkedList | |
![]() |
toArray():Array
Returns an array of all items in the present order.
| AbstractLinkedList | |
|
toString():String
Info
| LinkedMap | ||
| Method | Defined by | ||
|---|---|---|---|
![]() |
addFirstNode(node:LinkedNode):void
Adds the first node to an empty list.
| AbstractLinkedList | |
![]() |
Inserts a new node after an existing one.
| AbstractLinkedList | |
![]() |
addNodeAtEnd(node:LinkedNode):void
Inserts a new node at the end of the sequence.
| AbstractLinkedList | |
![]() |
addNodeAtStart(node:LinkedNode):void
Inserts a new node at the start of the sequence.
| AbstractLinkedList | |
![]() |
Inserts a new node before an existing one.
| AbstractLinkedList | |
|
deregisterNode(node:LinkedNode):void
Deregisters a node from the internal map.
| LinkedMap | ||
![]() |
getNodeAt(index:uint):LinkedNode
Returns the node at a specific position.
| AbstractLinkedList | |
![]() |
insertionSort(comparator:IComparator):void
Insertion sort algorithm.
| AbstractLinkedList | |
![]() |
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 | ||
|
nodeReplaced(node:LinkedNode):void
Template method to notify subclasses after a node has been replaced.
| LinkedMap | ||
|
registerNode(node:LinkedNode):void
Registers a node in the internal map.
| LinkedMap | ||
![]() |
unlinkFirstNode():void
Unlinks the first node of the sequence.
| AbstractLinkedList | |
![]() |
unlinkLastNode():void
Unlinks the last node of the sequence.
| AbstractLinkedList | |
![]() |
unlinkNode(node:LinkedNode):void
Unlinks a node and connects predecessor with successor.
| AbstractLinkedList | |
|
willRemoveNode(node:LinkedNode):void
Template method to notify subclasses when a node is about to be removed.
| LinkedMap | ||
| _map | property |
protected var _map:IMapThe internal map.
| LinkedMap | () | constructor |
public function LinkedMap()Creates a new LinkedMap instance.
| 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.
|
| addItemAfterNode_internal | () | method |
as3_collections function addItemAfterNode_internal(leftNode:LinkedMapNode, key:*, item:*):BooleanFramework internal method to add an item after an existing node.
ParametersleftNode: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.
|
Boolean — true, if the node has been added and false, if the key already exists.
|
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:*):BooleanAdds an item at the end of the linked map.
If the key already exists, the map will stay untouched and the method returns false.
Parameterskey:* — The key.
|
|
item:* — The item to be added at the end.
|
Boolean — true, if the item has been added or false, if the key already exists.
|
UnsupportedTypeException — If the key type does not match
with the type of the internal map.
|
| addItemAtStart | () | method |
public function addItemAtStart(key:*, item:*):BooleanAdds an item in front of the linked map.
If the key already exists, the map will stay untouched and the method returns false.
Parameterskey:* — The key.
|
|
item:* — The item to be added at start.
|
Boolean — true, if the item has been added or false, if the key already exists.
|
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:*):Booleanas3_collections
ParametersrightNode:LinkedMapNode |
|
key:* |
|
item:* |
Boolean |
| clear | () | method |
public override function clear():voidClears 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):voidDeregisters a node from the internal map.
Parametersnode:LinkedNode — The node to deregister.
|
| 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 override function getIterator(cursor:uint = 0):IIteratorReturns 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.
Parameterscursor:uint (default = 0) — Start position.
|
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.
Costs and order the same as for the iterator.
Parameterscursor:uint (default = 0) — Start position of the enumeration.
|
IIterator —
The key iterator.
|
See also
| 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.
|
| getPointer | () | method |
public function getPointer(key:*):IMapPointerReturns a map pointer for the linked map.
Parameterskey:* — The key for the item, the pointer should point to initially (optional).
|
IMapPointer —
The map pointer to modify the linked map.
|
| 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:LinkedNode):voidTemplate method to notify subclasses after a new node has been added.
Parametersnode:LinkedNode — The last added node.
|
| nodeRemoved | () | method |
protected function nodeRemoved():voidCommits the removal of the node, announced in willRemoveNode()
| nodeReplaced | () | method |
protected function nodeReplaced(node:LinkedNode):voidTemplate method to notify subclasses after a node has been replaced.
Parametersnode:LinkedNode — The replaced node.
|
| registerNode | () | method |
protected function registerNode(node:LinkedNode):voidRegisters a node in the internal map.
Parametersnode:LinkedNode — The node to register.
|
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.
Parameterskey:* — The key.
|
* — 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):BooleanFramework internal method to remove a node.
The method may be called with a null valued node.
Parametersnode:LinkedMapNode — The node to remove.
|
Boolean — true, if the node has been removed or false, if the given node is null.
|
| 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.
|
| toString | () | method |
public function toString():StringInfo
ReturnsString |
| willRemoveNode | () | method |
protected function willRemoveNode(node:LinkedNode):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:LinkedNode — The node that will be removed soon.
|