<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Thanks, this clarifies it.<div class="">Much obliged.</div><div class=""><br class=""></div><div class="">V/<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 28 Feb 2020, at 11:56, Jesper Louis Andersen <<a href="mailto:jesper.louis.andersen@gmail.com" class="">jesper.louis.andersen@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><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 class=""></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">L1 = [{X, X} || X <- lists:seq(1,32)].<br class=""></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">L1 == maps:to_list(maps:from_list(L1)).<br class="">true<br class=""></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br class=""></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 class="">false<br class=""></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br class=""></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 class=""></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 class=""><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" class="">v@micic.co.za</a>> wrote:<br class=""></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;" class="">Hi<div class=""><br class=""></div><div class="">Even though documentation indicates that:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Courier" class="">to_list(Map) -> [{Key, Value}]</font></div><div class="">
<h3 class=""><font face="Courier" class="">Types</font></h3>
<div class=""><span class=""><font face="Courier" class="">Map = map()</font></span></div>
<div class=""><span class=""><font face="Courier" class="">Key = Value = term()</font></span></div>
<div class=""><font face="Courier" class=""><span class=""></span></font></div>
</div><div class=""><font face="Courier" class=""><br class=""></font></div>
<div class=""><div class="">
<font face="Courier" class=""><br class=""></font></div><p class=""><font face="Courier" class="">Returns a list of pairs representing the key-value associations of
<span class="">Map</span>, where the pairs
<span class="">[{K1,V1}, ..., {Kn,Vn}]</span> <b class=""><i class="">are returned in arbitrary order.</i></b></font></p><div class="">It appears that the list returned has been sorted in ascending order, using value of the key as a criterion for sorting.</div><div class="">I did some testing using a bit modified example offered in documentation:</div><div class=""><br class=""></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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">(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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">[{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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> {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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> {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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> {"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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class=""><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Courier;color:rgb(255,238,149);background-color:rgb(78,78,78)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">(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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">(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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">[{-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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> {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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> {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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> {"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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Could one relay on this always being the case?</span></div><div class="">A I need this list to be sorted, I would hate to attempt sorting the already sorted list.</div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Thanks in advance</span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class="">V/</span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div></div></div></div></blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail_signature">J.</div>
</div></blockquote></div><br class=""></div></body></html>