日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

emmap erlang_erlang的map基本使用

發布時間:2025/3/15 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 emmap erlang_erlang的map基本使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

maps

適用于需要在運行時改變數據結構(record則不行)的場景,可以動態增加key

數據量不宜過大,具體多大沒有實際數據,

maps from_list ?如果list表很長,則相應的耗時時間會很長,此時最好用lists模塊。

由于map是動態結構,速度上必然無法匹敵record。

內存大小介于tuple與list之間

lists:sort([1,#{}, {}, []]).

[1,{},#{},[]]

Operations

Records

Maps

Dict

Immutable

?

?

?

Keys of any type

?

?

Usable with maps/folds

?

?

Content opaque to other modules

?

Has a module to use it

?

?

Supports pattern matching

?

?

All keys known at compile-time

?

Can merge with other instance

?

?

Testing for presence of a key

?

?

Extract value by key

?

?

?

Per-key Dialyzer type-checking

?

*

Conversion from/to lists

?

?

Per-element default values

?

Standalone data type at runtime

?

Fast direct-index access

?

* The EEP recommends making this possible for keys known at compile-time, but has no ETA on when or if this will happen.

示例代碼

-module(test).-compile([export_all]).%maps:% find/2 fold/3 from_list/1 get/2 get/3

% is_key/2 keys/1 map/2 merge/2 module_info/0

% module_info/1 new/0 put/3 remove/2 size/1

% to_list/1 update/3 values/1 with/2 without/2start()->A= #{k1 => 1, k2 => 2, k3 => 3},

#{k1 := K1} =A,

A1= A#{ k1 := K1 + 1}.%make()->

% maps: new |from_list

M1=maps:new(),%insert new one

M2= M1#{ k1 => 1},%update

M3= M2#{ k1 := 2},%maps 模塊封裝了一些函數

maps:put(k2,2, M3).%匹配

match(#{k1 := K1}) -> io:format("~p ~n", [K1]);

match(#{nothing := N}) -> io:format("~p ~n", [N]).

raw()->[ {I, I}|| I

get()->L=raw(),

lists:keyfind(999, 1, L).

get2()->M=maps:from_list(raw()),

maps:get(999, M).

更多閱讀:

http://learnyousomeerlang.com/maps

http://erlang.org/doc/man/maps.html

總結

以上是生活随笔為你收集整理的emmap erlang_erlang的map基本使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。