Class Hashmap

Description

Implementation of a hash table, that maps keys to values

The keys must be not null and not empty, and can't be duplicated. The values can be of any type.

Located in /core/util/Hashmap.class.php (line 41)

PHP2Go
   |
   --Hashmap
Variable Summary
array $elements
Method Summary
Hashmap Hashmap ([array $arr = array()])
mixed assertGet (string $key, string $type, [mixed $fallback = NULL])
bool assertType (string $key, string $type)
void clear ()
bool containsKey (string $key)
bool containsValue (mixed $value, [bool $strict = FALSE])
void customSort (string|array $callback)
mixed get (string $key, [mixed $fallback = NULL])
bool isEmpty ()
array keys ()
void merge (array|Hashmap $collection, [bool $recursive = FALSE])
bool put (string $key, mixed $value)
bool putAll (array $collection)
bool putRef (string $key, mixed &$value)
bool remove (string $key)
void reverseSort ([int $flags = SORT_REGULAR])
int size ()
void sort ([int $flags = SORT_REGULAR])
bool swap (string $a, string $b)
array toArray ()
array values ()
string __toString ()
Variables
array $elements = array() (line 49)

Map elements

  • access: private
Methods
Constructor Hashmap (line 57)

Class constructor

Hashmap Hashmap ([array $arr = array()])
  • array $arr: Initializes the map with the given array
assertGet (line 144)

Get the value of a given map entry, requiring it to be of a given type

The fallback value is returned when the key is not found or when the value is of a different data type.

Accepted types: string, integer, float, double, array, hash, resource, boolean, bool, object, null.

mixed assertGet (string $key, string $type, [mixed $fallback = NULL])
  • string $key: Key
  • string $type: Required type
  • mixed $fallback: Fallback value
assertType (line 175)

Checks if a key exists, and if its value is of a given type

Accepted types: string, integer, float, double, array, hash, resource, boolean, bool, object, null.

bool assertType (string $key, string $type)
  • string $key: Key
  • string $type: Required type
clear (line 114)

Clears the map

void clear ()
containsKey (line 218)

Checks if a given key exists

bool containsKey (string $key)
  • string $key: Key
containsValue (line 229)

Checks if a given value exists

bool containsValue (mixed $value, [bool $strict = FALSE])
  • mixed $value: Value
  • bool $strict: Whether data type must be checked
customSort (line 305)

Sorts the map by values based on an user-defined comparison function

void customSort (string|array $callback)
  • string|array $callback: User defined function
get (line 125)

Get an element of the map, given its key

mixed get (string $key, [mixed $fallback = NULL])
  • string $key: Key
  • mixed $fallback: Fallback value, to be used when the key is not found
isEmpty (line 323)

Checks if the map is empty

bool isEmpty ()
keys (line 199)

Get hash keys

array keys ()
merge (line 239)

Merge the hash with another collection

void merge (array|Hashmap $collection, [bool $recursive = FALSE])
  • array|Hashmap $collection: Collection
  • bool $recursive: Recursive merge
put (line 69)

Adds or changes a key-value pair

bool put (string $key, mixed $value)
  • string $key: Key
  • mixed $value: Value
putAll (line 100)

Adds all members of a collection in the map

bool putAll (array $collection)
  • array $collection: Collection
putRef (line 85)

Adds or changes a key passing the value by reference

bool putRef (string $key, mixed &$value)
  • string $key: Key
  • mixed &$value: Value
remove (line 273)

Removes a given key from the map

bool remove (string $key)
  • string $key: Key
reverseSort (line 296)

Sorts the map in reverse order (highest to lowest)

void reverseSort ([int $flags = SORT_REGULAR])
  • int $flags: Sort flags
size (line 314)

Get map size

int size ()
sort (line 287)

Sorts the map

void sort ([int $flags = SORT_REGULAR])
  • int $flags: Sort flags
swap (line 257)

Swap the values of two map keys

bool swap (string $a, string $b)
  • string $a: First key
  • string $b: Second key
toArray (line 332)

Builds an array representation of the hash map

array toArray ()
values (line 208)

Get hash values

array values ()
__toString (line 341)

Builds a string representation of the hash map

string __toString ()

Redefinition of:
PHP2Go::__toString()
Generate a string representation of the object

Inherited Methods

Inherited From PHP2Go

PHP2Go::PHP2Go()
PHP2Go::equals()
PHP2Go::generateUniqueId()
PHP2Go::getClassName()
PHP2Go::getConfigVal()
PHP2Go::getLangVal()
PHP2Go::getObjectName()
PHP2Go::getParentName()
PHP2Go::hasDestructor()
PHP2Go::hashCode()
PHP2Go::isA()
PHP2Go::isSubclassOf()
PHP2Go::logError()
PHP2Go::raiseError()
PHP2Go::registerDestructor()
PHP2Go::registerShutdownFunc()
PHP2Go::retrieve()
PHP2Go::store()
PHP2Go::__toString()

Documentation generated on Sun, 07 Oct 2007 19:25:53 -0300 by phpDocumentor 1.3.2