<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">No, and it is subtle:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">L1 = [{X, X} || X <- lists:seq(1,32)].<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">L1 == maps:to_list(maps:from_list(L1)).<br>true<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">L2 = [{X, X} || X <- lists:seq(1,33)].</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">L2 == maps:to_list(maps:from_list(L2)).<br>false<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">At 32+ elements, Maps change their representation order to a hash array mapped trie. These are not generally ordered, but provide very fast lookups. In practice you are O(1) bound with a couple of memory reads. In theory you are O(lg n) bound width a branch factor of 32.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">If you need the order, you need to use a representation which maintains the order.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 28, 2020 at 10:45 AM Valentin Micic <<a href="mailto:v@micic.co.za">v@micic.co.za</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;">Hi<div><br></div><div>Even though documentation indicates that:</div><div><br></div><div><div><font face="Courier">to_list(Map) -> [{Key, Value}]</font></div><div>
<h3><font face="Courier">Types</font></h3>
<div><span><font face="Courier">Map = map()</font></span></div>
<div><span><font face="Courier">Key = Value = term()</font></span></div>
<div><font face="Courier"><span></span></font></div>
</div><div><font face="Courier"><br></font></div>
<div><div>
<font face="Courier"><br></font></div><p><font face="Courier">Returns a list of pairs representing the key-value associations of
<span>Map</span>, where the pairs
<span>[{K1,V1}, ..., {Kn,Vn}]</span> <b><i>are returned in arbitrary order.</i></b></font></p><div>It appears that the list returned has been sorted in ascending order, using value of the key as a criterion for sorting.</div><div>I did some testing using a bit modified example offered in documentation:</div><div><br></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)"><span style="font-variant-ligatures:no-common-ligatures">(x@MacBook-Pro)47> f(Map), Map = #{42 => value_three,1337 => "value two","a" => 1, 1 => "Last entered"},maps:to_list(Map). </span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)"><span style="font-variant-ligatures:no-common-ligatures">[{1,"Last entered"},</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)"><span style="font-variant-ligatures:no-common-ligatures"> {42,value_three},</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)"><span style="font-variant-ligatures:no-common-ligatures"> {1337,"value two"},</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)"><span style="font-variant-ligatures:no-common-ligatures"> {"a",1}]</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><br></div><div><br></div><div>When I changed 1337 to -1337, I get the result that indicates that the list of pairs is *not* returned in arbitrary order, but actually sorted:</div><div><br></div><div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)"><span style="font-variant-ligatures:no-common-ligatures">(x@MacBook-Pro)48> </span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)"><span style="font-variant-ligatures:no-common-ligatures">(x@MacBook-Pro)48> f(Map), Map = #{42 => value_three, -1337 => "value two","a" => 1, 1 => "Last entered"},maps:to_list(Map).</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)"><span style="font-variant-ligatures:no-common-ligatures">[{-1337,"value two"},</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)"><span style="font-variant-ligatures:no-common-ligatures"> {1,"Last entered"},</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)"><span style="font-variant-ligatures:no-common-ligatures"> {42,value_three},</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)"><span style="font-variant-ligatures:no-common-ligatures"> {"a",1}]</span></div></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">Could one relay on this always being the case?</span></div><div>A I need this list to be sorted, I would hate to attempt sorting the already sorted list.</div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">Thanks in advance</span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">V/</span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div></div></div></div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">J.</div>