🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #2194

Re: Iterators over slices and views and ranges analogs in C

#2194
From: Ross Finlayson
Date: Fri, 04 Dec 2026 16:16
114 lines
6303 bytes
On 12/03/2026 11:22 PM, Ross Finlayson wrote:
> On 12/03/2026 04:59 PM, Kenny McCormack wrote:
>> In article <11esd12$mfam$1@raubtier-asyl.eternal-september.org>,
>> Bonita Montero  <Bonita.Montero@gmail.com> wrote:
>>> Better use C++ for what you want to do.
>>
>> Or Fortran.
>>
>> Or 8086 assembler.
>>
>> All better choices.
>>
>
> Browsing about the video pile for "iterators in C" there's
> a "Charles Severance" walks through what would be the usual
> sort of textbook example called "K & R" of "iterators in C".
> (I have a copy in my library of C and C++ books.)
>
>
> That Severance has quite a few good sorts of interviews and
> educations there from the video pile.
>
>
> Here the approach instead is about this viter/witer approach
> then for titer/uiter, with looking to align the state & change
> in, say, cache-line pairs, when for example the buffers are
> one of C_LINE/C_PAIR or M_PAGE/M_HUGE size, since a usual idea
> is that instead of linked-lists scattered throughout the heap
> which has random access, that mostly the data is in memory pages,
> those then carved from a slab, ....
>
>
> Getting that organized the viter/witer then titer/uiter, or
> the view-iter, write-iter, then tuple-view and tuple-write
> and unsigned-view and unsigned-write iters, seems a good idea
> since it's mostly always so that they're one or the other.
>
>
> It's agreeable that something like FORTRAN may be better for
> array-type languages, about though "array-languages" also
> there are a bunch of those like "APL" and this, here though
> there's considered a sort of least-common-denominator of
> a "C" compiler, if though writing only to a subset of the
> language.
>
>
>


So, one of the challenges I'm trying to figure out is this:
we all know account of pointers and links and linked-lists
and arrays and storage and memory, fine, that's among the
model of resources for the model of computation.


So, ..., usually that means "a fixed-length node, with a pointer,
to a datum". This is so for linked-lists, here just lists, and later
also for trees in a usual representation, links, as branches usually
for nodes as vertices for edges in a graph often enough, about
the language of "graph theory", vis-a-vis, the lattice and what's
much simpler as the account of "sequence", linked-lists.


So here's the challenge: let's say the datum is a memory page,
then also the node is sized a memory page, there's only one
size allocated. (These here are basically figured as cline/cpair
for cache-lines and cache-line-pairs, and mpage/mhuge for
4Kib/2Mib memory pages.)

So the challenge is that to make a list of length 1, that it's
given one page for the node, i.e. the link, and one page for
the datum or item. Then the node is mostly un-used space,
about that basically it's an array of links, and when adding
items, each just sees an allocation of another page and then
adding the entry as a link in the table or for the same amount
of memory.

How then to organize a table of links in a page, that has links
to the items, then, also perhaps a link to a next table, is about
basically making the list as doubly-linked to support insertions
that aren't to the head or tail or somewhere in the middle.

Then, for the account of arrays, for example when the initial
capacity of the list, or, "lodge", say, "lodging the list", has
basically about the patch-work of then _various_ size, basically
mhuge or mpage, about "capacity" and "organization" and
"re-organization" vis-a-vis "access", for example as by "iterators".

One may aver "that's way too complicated and is also a
different account than that slab-allocator approach being
talked about", and it is, about that the allocator is simplified
to only issue specific fixed sizes, though above just a byte
or word apiece and basically organized about the page,
mpage or mhuge, then "mgiga" say, then that making
access of this to follow the links involves iterating over
the elements in these tables, which start not being powers-of-two,
the ranges of those.


Anyways that's the idea under consideration for then making
an account of what an iterator would do, over any sort of
patchwork of arrays and what models these lodged-lists
then also link-lists for adapters to these (adapters/adaptors,
adapters usually), about usual cases where there are not
many deletions, as basically would result for nulling the tables
and patching the links, then reorganization as compaction,
since all the items are either built-in data-types or pointers,
which are built-in data-types, of fixed-size and a power of two.


This kind of thing, ....


Technical Details
Message-ID: <xdCdnbV1B7zLeo_2nZ2dnZfqnPp4dVTc@giganews.com>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-2.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-3.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
References: <-kGdnSzB4bWEM4z2nZ2dnZfqn_WdnZ2d@giganews.com> <11esd12$mfam$1@raubtier-asyl.eternal-september.org> <11et39b$rj55$1@news.xmission.com> <gWGdndhHmaii94_2nZ2dnZfqn_SdnZ2d@giganews.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-2.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-3.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 04 Dec 2026 16:16:22 +0000
Subject: Re: Iterators over slices and views and ranges analogs in C
Newsgroups: comp.lang.c
References: <-kGdnSzB4bWEM4z2nZ2dnZfqn_WdnZ2d@giganews.com>
 <11esd12$mfam$1@raubtier-asyl.eternal-september.org>
 <11et39b$rj55$1@news.xmission.com>
 <gWGdndhHmaii94_2nZ2dnZfqn_SdnZ2d@giganews.com>
From: Ross Finlayson <ross.a.finlayson@gmail.com>
Date: Fri, 4 Dec 2026 08:16:19 -0800
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.6.0
MIME-Version: 1.0
In-Reply-To: <gWGdndhHmaii94_2nZ2dnZfqn_SdnZ2d@giganews.com>
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <xdCdnbV1B7zLeo_2nZ2dnZfqnPp4dVTc@giganews.com>
Lines: 114
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-kzSS+MLOXpwEMlD6jBRFUPCEuI++qkCM8OuzX/kd3zEWDXMb4hoIOYLT3h+yHJWVySUwSMYlN6e6YSI!zuhzN6OSBM+zjHpReDk1NdJAwHjQh0ccooYqyI17Pc5gLU24Xufy0vNs97hfgOG323pAnxmlJ4s=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40