Packagede.polygonal.ds
Classpublic class HashMap
InheritanceHashMap Inheritance Object
Implements Collection

A hash table using direct lookup (perfect hashing). Each key can only map one value at a time and multiple keys can map the same value. The HashMap is preallocated according to an initial size, but afterwards automatically resized if the number of key-value pairs exceeds the predefined size.



Public Properties
 PropertyDefined By
  size : int
[read-only] The total number of items.
HashMap
Public Methods
 MethodDefined By
  
HashMap(size:int = 500)
Initializes a new HashMap instance.
HashMap
  
clear():void
Clears all items.
HashMap
  
contains(obj:*):Boolean
Determines if the collection contains a given item.
HashMap
  
containsKey(key:*):Boolean
Checks if a mapping exists for the given key.
HashMap
  
dump():String
Prints out all elements (for debug/demo purposes).
HashMap
  
find(key:*):*
Finds the value that is associated with the given key.
HashMap
  
Initializes an iterator object pointing to the first item in the collection.
HashMap
  
getKeySet():Array
Writes all keys into an array.
HashMap
  
insert(key:*, obj:*):Boolean
Inserts a key/data couple into the table.
HashMap
  
isEmpty():Boolean
Checks if the collection is empty.
HashMap
  
remove(key:*):*
Removes a value based on a given key.
HashMap
  
toArray():Array
Converts the collection into an array.
HashMap
  
toString():String
Prints out a string representing the current object.
HashMap
Property Detail
sizeproperty
size:int  [read-only]

The total number of items.


Implementation
    public function get size():int
Constructor Detail
HashMap()Constructor
public function HashMap(size:int = 500)

Initializes a new HashMap instance.

Parameters
size:int (default = 500) — The initial capacity of the HashMap.
Method Detail
clear()method
public function clear():void

Clears all items.

contains()method 
public function contains(obj:*):Boolean

Determines if the collection contains a given item.

Parameters

obj:* — The item to search for.

Returns
Boolean — True if the item exists, otherwise false.
containsKey()method 
public function containsKey(key:*):Boolean

Checks if a mapping exists for the given key.

Parameters

key:*

Returns
Boolean — True if key exists, otherwise false.
dump()method 
public function dump():String

Prints out all elements (for debug/demo purposes).

Returns
String — A human-readable representation of the structure.
find()method 
public function find(key:*):*

Finds the value that is associated with the given key.

Parameters

key:* — The key mapping a value.

Returns
* — The data associated with the key or null if no matching entry was found.
getIterator()method 
public function getIterator():Iterator

Initializes an iterator object pointing to the first item in the collection.

Returns
Iterator — An iterator object.
getKeySet()method 
public function getKeySet():Array

Writes all keys into an array.

Returns
Array — An array containing all keys.
insert()method 
public function insert(key:*, obj:*):Boolean

Inserts a key/data couple into the table.

Parameters

key:* — The key.
 
obj:* — The data associated with the key.

Returns
Boolean
isEmpty()method 
public function isEmpty():Boolean

Checks if the collection is empty.

Returns
Boolean — True if empty, otherwise false.
remove()method 
public function remove(key:*):*

Removes a value based on a given key.

Parameters

key:* — The entry's key.

Returns
* — The data associated with the key or null if no matching entry was found.
toArray()method 
public function toArray():Array

Converts the collection into an array.

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

Prints out a string representing the current object.

Returns
String — A string representing the current object.