<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - comments on Post, ListBuffer, a procedure for efficiently building arbitrarily sized lists</title>
    <link>http://www.mapleprimes.com/posts/43257-ListBuffer-A-Procedure-For-Efficiently</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Tue, 09 Jun 2026 06:51:09 GMT</lastBuildDate>
    <pubDate>Tue, 09 Jun 2026 06:51:09 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest comments added to the Post, ListBuffer, a procedure for efficiently building arbitrarily sized lists</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - comments on Post, ListBuffer, a procedure for efficiently building arbitrarily sized lists</title>
      <link>http://www.mapleprimes.com/posts/43257-ListBuffer-A-Procedure-For-Efficiently</link>
    </image>
    <item>
      <title>Quite nice</title>
      <link>http://www.mapleprimes.com/posts/43257-ListBuffer-A-Procedure-For-Efficiently?ref=Feed:MaplePrimes:ListBuffer, a procedure for efficiently building arbitrarily sized lists:Comments#comment80245</link>
      <itunes:summary>This particular trick &amp;mdash; dynamically building a table then converting to a list at the end &amp;mdash; is something I've used before in a number of places: it's really all you can do when you have to return a list of possibly arbitrary size.  However, this particular formalization is particularly nice.

I was curious to see how it scaled: since there is a bit of overhead to tables, would adding an element actually be linear with a very small coefficient?  It seems not, or at least this coefficient is very small indeed.

&lt;pre&gt;
N := 100000:
A := Array(1..N):
lb := ListBuffer():
for i from 1 to N do A[i] := time(lb:-append(i)): end do:
plots[pointplot]( [seq([j,A[j]], j=1..N]) );
&lt;/pre&gt;

The outliers in the plot are probably gc-related.</itunes:summary>
      <description>The latest comments added to the Post, ListBuffer, a procedure for efficiently building arbitrarily sized lists</description>
      <guid>80245</guid>
      <pubDate>Thu, 19 Jan 2006 20:24:18 Z</pubDate>
      <itunes:author>Stephen Forrest</itunes:author>
      <author>Stephen Forrest</author>
    </item>
    <item>
      <title>Link in post is dead</title>
      <link>http://www.mapleprimes.com/posts/43257-ListBuffer-A-Procedure-For-Efficiently?ref=Feed:MaplePrimes:ListBuffer, a procedure for efficiently building arbitrarily sized lists:Comments#comment144180</link>
      <itunes:summary>&lt;p&gt;I was looking for Joe's &lt;strong&gt;ListBuffer&lt;/strong&gt; code, but the (seven-year-old) link in the original post is dead.&lt;/p&gt;</itunes:summary>
      <description>The latest comments added to the Post, ListBuffer, a procedure for efficiently building arbitrarily sized lists</description>
      <guid>144180</guid>
      <pubDate>Tue, 05 Mar 2013 03:54:11 Z</pubDate>
      <itunes:author>Carl Love</itunes:author>
      <author>Carl Love</author>
    </item>
    <item>
      <title>Found</title>
      <link>http://www.mapleprimes.com/posts/43257-ListBuffer-A-Procedure-For-Efficiently?ref=Feed:MaplePrimes:ListBuffer, a procedure for efficiently building arbitrarily sized lists:Comments#comment144183</link>
      <itunes:summary>&lt;p&gt;I found it on the waybackmachine.&amp;nbsp; Here it is.&lt;/p&gt;
&lt;p&gt;&lt;a href="/view.aspx?sf=144183/455264/1_ListBuffer.mpl"&gt;1_ListBuffer.mpl&lt;/a&gt;&lt;/p&gt;</itunes:summary>
      <description>The latest comments added to the Post, ListBuffer, a procedure for efficiently building arbitrarily sized lists</description>
      <guid>144183</guid>
      <pubDate>Tue, 05 Mar 2013 07:25:14 Z</pubDate>
      <itunes:author>Christopher2222</itunes:author>
      <author>Christopher2222</author>
    </item>
    <item>
      <title>Page Not Found</title>
      <link>http://www.mapleprimes.com/posts/43257-ListBuffer-A-Procedure-For-Efficiently?ref=Feed:MaplePrimes:ListBuffer, a procedure for efficiently building arbitrarily sized lists:Comments#comment205496</link>
      <itunes:summary>&lt;p&gt;&lt;a href="/posts/43257-ListBuffer-A-Procedure-For-Efficiently#comment144183"&gt;@Christopher2222&lt;/a&gt;&amp;nbsp;Unfortunately, the link is dead again, but as I see it, wasn&amp;#39;t a (table-based array)-based vector or a one-dimensional Array enough at that time? (And was the use of a&amp;nbsp;&lt;a href="https://www.maplesoft.com/support/help/Maple/view.aspx?path=examples%2FLinkedListPackage"&gt;linked list&lt;/a&gt;&amp;nbsp;recommended in this situation?) If I have understood correctly, nowadays a better choice should be the newer &lt;a href="https://www.maplesoft.com/support/help/Maple/view.aspx?path=DEQueue"&gt;DEQueue&lt;/a&gt;&amp;nbsp;object.&lt;br&gt;
By the way, is there a similar&amp;nbsp;&lt;a href="https://docs.scala-lang.org/overviews/collections-2.13/performance-characteristics.html"&gt;performance characteristic&lt;/a&gt;&amp;nbsp;of the built-in&amp;nbsp;&lt;code&gt;StringTools:-StringBuffer&lt;/code&gt;?&lt;/p&gt;
</itunes:summary>
      <description>The latest comments added to the Post, ListBuffer, a procedure for efficiently building arbitrarily sized lists</description>
      <guid>205496</guid>
      <pubDate>Fri, 22 Sep 2023 03:36:53 Z</pubDate>
      <itunes:author>sursumCorda</itunes:author>
      <author>sursumCorda</author>
    </item>
    <item>
      <title>Four efficient list-building methods</title>
      <link>http://www.mapleprimes.com/posts/43257-ListBuffer-A-Procedure-For-Efficiently?ref=Feed:MaplePrimes:ListBuffer, a procedure for efficiently building arbitrarily sized lists:Comments#comment205497</link>
      <itunes:summary>&lt;p&gt;&lt;a href="/posts/43257-ListBuffer-A-Procedure-For-Efficiently#comment205496"&gt;@sursumCorda&lt;/a&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;Linked-lists or queues are quite unnecessarily elaborate for this purpose. So-called &amp;quot;flat&amp;quot; and semantics-free containers (rtables, tables) are enough.&lt;/p&gt;

&lt;p&gt;Here are four efficient methods to build a Maple list:&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
&lt;strong&gt;#Note the use of [ ] in this procedure:&lt;/strong&gt;&lt;span style="color:#c0392b;"&gt;&lt;strong&gt;
Nprimes_do:= (n::posint)-&amp;gt; 
local p, i:= 0;
    [for p do if gmp_isprime(p) then i++; p fi until i=n]
:
&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;#Note the use of ,= in this procedure:&lt;/strong&gt;&lt;span style="color:#c0392b;"&gt;&lt;strong&gt;
Nprimes_Array:= proc(n::posint)
local P:= Array(1..0), p; 
    for p do if gmp_isprime(p) then i++; P,= p fi until i=n;
    [seq](P)
end proc
:
Nprimes_indices:= proc(n::posint)
local P, p, i:= 0;
    for p do if gmp_isprime(p) then P[p]:= ++i fi until i=n;
    [indices](P, &amp;#39;nolist&amp;#39;, &amp;#39;indexorder&amp;#39;)
end proc
:
Nprimes_entries:= proc(n::posint)
local P, p, i:= 0;
    for p do if gmp_isprime(p) then P[++i]:= p fi until i=n;
    [entries](P, &amp;#39;nolist&amp;#39;, &amp;#39;indexorder&amp;#39;)
end proc
:    
[
    for P in Nprimes||(_do, _Array, _indices, _entries) do
        lprint(eval(P,1)); gc(); CodeTools:-Usage(P(2^17))[-1]
    od
];&lt;/strong&gt;&lt;/span&gt;
&lt;span style="color:#0000ff;"&gt;Nprimes_do
memory used=175.73MiB, alloc change=16.45MiB,
cpu time=1.22s, real time=1.22s, gc time=0ns
Nprimes_Array
memory used=123.83MiB, alloc change=2.01MiB, 
cpu time=1.12s, real time=1.13s, gc time=0ns
Nprimes_indices
memory used=136.72MiB, alloc change=2.01MiB,
cpu time=1.24s, real time=1.23s, gc time=0ns
Nprimes_entries
memory used=136.77MiB, alloc change=1.00MiB,
cpu time=1.23s, real time=1.24s, gc time=0ns

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [1742537, 1742537, 1742537, 1742537]&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;Yes,&amp;nbsp;&lt;strong&gt;ListBuffer&amp;nbsp;&lt;/strong&gt;is obsolete.&lt;/p&gt;

&lt;p&gt;And I think that the code above shows that your argument from several months ago about&amp;nbsp;&lt;strong&gt;for&lt;/strong&gt;&amp;nbsp;loops being inefficient (based on your misreading of a poorly written and out-of-date help-page passage) is incorrect.&lt;/p&gt;
</itunes:summary>
      <description>The latest comments added to the Post, ListBuffer, a procedure for efficiently building arbitrarily sized lists</description>
      <guid>205497</guid>
      <pubDate>Fri, 22 Sep 2023 09:59:01 Z</pubDate>
      <itunes:author>Carl Love</itunes:author>
      <author>Carl Love</author>
    </item>
    <item>
      <title>Performance-bound guarantees?</title>
      <link>http://www.mapleprimes.com/posts/43257-ListBuffer-A-Procedure-For-Efficiently?ref=Feed:MaplePrimes:ListBuffer, a procedure for efficiently building arbitrarily sized lists:Comments#comment205499</link>
      <itunes:summary>&lt;p&gt;&lt;a href="/posts/43257-ListBuffer-A-Procedure-For-Efficiently#comment205497"&gt;@Carl Love&lt;/a&gt;&amp;nbsp;Thanks for your clarification.&amp;nbsp;&lt;/p&gt;

&lt;p&gt;Though &amp;quot;exprseq&amp;quot; is not a valid type, I&amp;#39;d like to know if the `,=` operation for an existing expression sequence (not a 1-dimensional rtable) is potentially inefficient. In Maple, &amp;quot;set&amp;quot; is a immutable structure, so the `union=` manipulation can be less efficient when incrementally building up the large set from its members. Will the use of `,=` add a significant amount of processing time to certain computations as well?&lt;/p&gt;
</itunes:summary>
      <description>The latest comments added to the Post, ListBuffer, a procedure for efficiently building arbitrarily sized lists</description>
      <guid>205499</guid>
      <pubDate>Fri, 22 Sep 2023 14:47:23 Z</pubDate>
      <itunes:author>sursumCorda</itunes:author>
      <author>sursumCorda</author>
    </item>
  </channel>
</rss>