The map of Erlang is basically used

Source: Internet
Author: User

Maps

For scenarios where you need to change the data structure at run time (record does not), you can dynamically add key

The amount of data should not be too large, specific how big no actual data,

Maps From_list If the list table is long, then the corresponding time will be very long, it is best to use the lists module.

Because map is a dynamic structure, the speed must not match the record.

Memory size between tuple and list

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

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

Operations Records Maps Dict
Immutable ? ? ?
Keys of any type ? ?
Usable with Maps/folds ? ?
Content Opaque to other modules ?
Have 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 have no ETA on when or if this would happen.

Sample code

-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 VA LUES/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},    %The maps module encapsulates some function maps:put (K2,2, M3).%matches match (#{k1:= K1}), Io:format ("~p ~n", [K1]); Match (#{nothing:= N}), Io:format ("~p ~n", [N]). Raw ()-[{i, i}|| I <-lists:seq (1, 10000000)].get ()-L=Raw (), Lists:keyfind (999, 1, L). Get2 ()-M=maps:from_list (Raw ()), Maps:get (999, M).

Read MORE:

Http://learnyousomeerlang.com/maps

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

The map of Erlang is basically used

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.