Data Structures
PHP Manual

The Map class

(No version information available, might only be in Git)

Introduction

A Map is a sequential collection of key-value pairs, almost identical to an array used in a similar context. Keys can be any type, but must be unique. Values are replaced if added to the map using the same key.

Strengths

  • Keys and values can be any type, including objects.
  • Supports array syntax (square brackets).
  • Insertion order is preserved.
  • Performance and memory efficiency is very similar to an array.
  • Automatically frees allocated memory when its size drops low enough.

Weaknesses

  • Can’t be converted to an array when objects are used as keys.

Class synopsis

Ds\Map implements Ds\Collection {
/* Constants */
const int MIN_CAPACITY = 16 ;
/* Methods */
public void allocate ( int $capacity )
public void apply ( callable $callback )
public int capacity ( void )
public void clear ( void )
public Ds\Map copy ( void )
public Ds\Map diff ( Ds\Map $map )
public Ds\Map filter ([ callable $callback ] )
public Ds\Pair first ( void )
public mixed get ( mixed $key [, mixed $default ] )
public bool hasKey ( mixed $key )
public bool hasValue ( mixed $value )
public Ds\Map intersect ( Ds\Map $map )
public bool isEmpty ( void )
public Ds\Set keys ( void )
public void ksort ([ callable $comparator ] )
public Ds\Map ksorted ([ callable $comparator ] )
public Ds\Pair last ( void )
public Ds\Map map ( callable $callback )
public Ds\Map merge ( mixed $values )
public Ds\Sequence pairs ( void )
public void put ( mixed $key , mixed $value )
public void putAll ( mixed $pairs )
public mixed reduce ( callable $callback [, mixed $initial ] )
public mixed remove ( mixed $key [, mixed $default ] )
public void reverse ( void )
public Ds\Map reversed ( void )
public Ds\Pair skip ( int $position )
public Ds\Map slice ( int $index [, int $length ] )
public void sort ([ callable $comparator ] )
public Ds\Map sorted ([ callable $comparator ] )
public number sum ( void )
public array toArray ( void )
public Ds\Map union ( Ds\Map $map )
public Ds\Sequence values ( void )
public Ds\Map xor ( Ds\Map $map )
}

Predefined Constants

Ds\Map::MIN_CAPACITY

Table of Contents


Data Structures
PHP Manual