首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Map (class)

介绍

(没有可用的版本信息,可能只在Git中)

一个Map是键值对的一个顺序集合,与在类似的上下文中使用的数组几乎相同。键可以是任何类型,但必须是唯一的。如果使用相同的密钥添加到地图,则值将被替换。

优势

  • 键和值可以是任何类型,包括对象。
  • 支持数组语法(方括号)。
  • 插入顺序被保留。
  • 性能和内存效率与阵列非常相似。
  • 当大小下降得足够小时,自动释放分配的内存。

弱点

当对象用作键时无法转换为数组。

类概要

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 ConstantsDs\Map::MIN_CAPACITY

目录

  • Ds \ Map :: allocate - 为所需容量分配足够的内存。
  • Ds \ Map :: apply - 通过对每个值应用回调函数来更新所有值。
  • Ds \ Map :: capacity - 返回当前容量。
  • Ds \ Map :: clear - 删除所有值。
  • Ds \ Map :: __ construct - 创建一个新实例。
  • Ds \ Map :: copy - 返回Map的浅表副本。
  • Ds \ Map :: count - 返回Map中值的数量。
  • Ds \ Map :: diff - 使用不在另一个Map中的键创建新Map。
  • Ds \ Map :: filter - 使用callable创建一个新map来确定要包含哪些对。
  • Ds \ Map :: first - 返回map中的第一对。
  • Ds \ Map :: get - 返回给定键的值。
  • Ds \ Map :: hasKey - 确定map是否包含给定的键。
  • Ds \ Map :: hasValue - 确定map是否包含给定值。
  • Ds \ Map :: intersect - 通过将键与另一个map相交来创建新map。
  • Ds \ Map :: isEmpty - 返回map是否为空
  • Ds \ Map :: jsonSerialize - 返回可以转换为JSON的表示。
  • Ds \ Map :: keys - 返回一组映射的键。
  • Ds \ Map :: ksort - 按键对map进行排序。
  • Ds \ Map :: ksorted - 返回一个副本,按键排序。
  • Ds \ Map :: last - 返回map的最后一对。
  • Ds \ Map :: merge - 返回添加所有给定关联的结果。
  • Ds \ Map :: pairs - 返回一个包含map所有对的序列。
  • Ds \ Map :: put - 将键与一个值关联。
  • Ds \ Map :: putAll - 关联可遍历对象或数组的所有键值对。
  • Ds \ Map :: reduce - 使用回调函数将映射缩减为单个值。
  • Ds \ Map :: remove - 通过键删除并返回一个值。
  • Ds \ Map :: reverse - 在原位置颠倒map。
  • Ds \ Map :: reversed - 返回一个颠倒的副本。
  • Ds \ Map :: skip - 返回给定位置索引处的对。
  • Ds \ Map :: slice - 返回由起始索引和长度定义的映射的子集。
  • Ds \ Map :: sort - 按照值对map进行排序。
  • Ds \ Map :: sorted - 返回一个副本,按值排序。
  • Ds \ Map :: sum - 返回map中所有值的总和。
  • Ds \ Map :: toArray - 将map转换为数组。
  • Ds \ Map :: union - 使用当前实例和另一个map中的值创建新map。
  • Ds \ Map :: values - 返回map值的序列。
  • Ds \ Map :: xor - 使用当前实例或另一个map的键创建新map,但不是两者。

← Ds\Deque::unshift

Ds\Map::allocate →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com