<div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">On Sat, Jan 26, 2019 at 6:29 PM Fred Youhanaie <<a href="mailto:fly@anydata.co.uk">fly@anydata.co.uk</a>> wrote:<br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">That's part of the internal structure of the array module, the data structure is opaque and should not be relied upon.<br>
<br></blockquote></div><div class="gmail_quote"><br></div><div class="gmail_quote"><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">For full reference, you can glean on the internal structure:</div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default"><br></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">Erlang/OTP 21 [erts-10.2.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]<br><br>Eshell V10.2.1 (abort with ^G)<br>1> rr(array).<br>[array]<br>2> array:new(19, {default, {0, unspecified, 0}}).<br>#array{size = 19,max = 0,<br> default = {0,unspecified,0},<br> elements = 100}<br>3> array:new(9, {default, {0, unspecified, 0}}).<br>#array{size = 9,max = 0,<br> default = {0,unspecified,0},<br> elements = 10}<br></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default"><br></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">Here is what is happening: In Erlang, an Array is a very flat tree with a branching factor of 10. It is stored in `elements`. But instead of storing a tree, you may store an integer encoding how much more space is allowed in this part of the tree when it is expanded. You have created a tree of size 19, which means it needs two expansions of size 10, or 100---though not all of those expansions will be used, as it is extra padding. If you had created an array of size 101, it would have been 1000, and so on. It is always the next log10 ceiling value. In the example with size 9, only one expansion is needed in which case we have a `10` in the elements.</div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default"><br></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">You might ask why it isn't represented as a traditional array. This is because of persistence in data structures: older versions of the tree can be kept alive, so you cannot overwrite an older array. It is useful in a number of situations, the most important one being that you can know the state of a crashing process before it crashed, and what event led to said crash.<br></div><br></div></div></div>