Map with associative array in PHP

This is a relatively straightforward implementation of a PHP Map that uses associative PHP array as data storage. custom research paper

The Solution

require_once('ig/util/AbstractMap.class.php');
 
/**
 * Map that uses an associative array.
 *
 * @author Ivan Georgiev
 */
 
class ig_util_AssocMap extends ig_util_AbstractMap {
	var $data = array();
 
	/**
	 * @return ig_util_AbstractMap
	 */
	function & Create() {
		$map =& new ig_util_AssocMap();
		return $map;
	}
 
	function clear() {
		$this->data = array();
	}
 
	function containsKey($key) {
		return array_key_exists($key, $this->data);
	}
 
	function & get($key) {
		if ($this->containsKey($key)) $value =& $this->data[$key];
		else $value = false;
		return $value;
	}
 
	function isEmpty() {
		return empty($this->data);
	}
 
	function keyArray() {
		return array_keys($this->data);
	}
 
	function put($key, &$value) {
		$this->data[$key] =& $value;
	}
 
	function remove($key) {
		if ($this->containsKey($key)) unset($this->data[$key]);
	}
 
	function size() {
		return count($this->data);
	}
}

See also: Unit tests for PHP Map implementation with associative array, Abstract key-value Map in PHP

 
php/util/assocmap.txt · Last modified: 2010/06/04 11:34 by nikkiturner1203
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki