📜  Erlang-地图

📅  最后修改于: 2020-11-04 05:54:07             🧑  作者: Mango


映射是具有可变数量的键值关联的复合数据类型。映射中的每个键-值关联称为关联对。该对中的键和值部分称为元素。关联对的数量被称为地图的大小。

以下程序显示了如何使用Map数据类型的示例。

在这里,我们定义了具有2个映射的Map M1。 map_size是用Erlang定义的内置函数,可用于确定地图的大小。

-module(helloworld). 
-export([start/0]). 

start() -> 
   M1 = #{name=>john,age=>25}, 
   io:fwrite("~w",[map_size(M1)]).

上述程序的输出如下。

输出

2

适用于地图的其他一些方法如下。

Sr.No. Methods & Description
1

from_list

This method is used to generate a map from a list.

2

find

This method is used to find if a particular key exists in the map.

3

get

This method is used to get the value of a particular key in the map.

4

is_key

This method is used to determine if a particular key is defined as a key in the map.

5

keys

This method is used to return all the keys from a map.

6

merge

This method is used to merge 2 maps.

7

put

This method is used to add a key value pair to the map.

8

values

This method is used to return all the values from a map.

9

remove

This method is used to remove a key value from the map.