Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"The medium is the massage." -- Crazy Nigel


devel / comp.lang.ada / Map iteration and modification

SubjectAuthor
* Map iteration and modificationDrPi
`* Re: Map iteration and modificationDrPi
 +* Re: Map iteration and modificationDmitry A. Kazakov
 |+- Re: Map iteration and modificationDrPi
 |`* Re: Map iteration and modificationRandy Brukardt
 | `* Re: Map iteration and modificationDmitry A. Kazakov
 |  +* Re: Map iteration and modificationG.B.
 |  |`* Re: Map iteration and modificationDmitry A. Kazakov
 |  | `* Re: Map iteration and modificationG.B.
 |  |  `* Re: Map iteration and modificationDmitry A. Kazakov
 |  |   +* Re: Map iteration and modificationG.B.
 |  |   |`- Re: Map iteration and modificationDmitry A. Kazakov
 |  |   `* Re: Map iteration and modificationRandy Brukardt
 |  |    `- Re: Map iteration and modificationmoi
 |  `* Re: Map iteration and modificationRandy Brukardt
 |   `* Re: Map iteration and modificationDmitry A. Kazakov
 |    `* Re: Map iteration and modificationRandy Brukardt
 |     `* Re: Map iteration and modificationDmitry A. Kazakov
 |      `* Re: Map iteration and modificationRandy Brukardt
 |       `* Re: Map iteration and modificationDmitry A. Kazakov
 |        `* Re: Map iteration and modificationRandy Brukardt
 |         +- Re: Map iteration and modificationSimon Wright
 |         +* Re: Map iteration and modificationDmitry A. Kazakov
 |         |+* Re: Map iteration and modificationRandy Brukardt
 |         ||`* Re: Map iteration and modificationJeffrey R.Carter
 |         || `* Re: Map iteration and modificationRandy Brukardt
 |         ||  +- Re: when-clauses (was Re: Map iteration and modification)Lawrence D'Oliveiro
 |         ||  `- Re: Map iteration and modificationJeffrey R.Carter
 |         |`- Re: Map iteration and modificationCóilín Nioclás Pól Glostéir
 |         `* Re: “Usability” (was Re: Map iteration and modification)Lawrence D'Oliveiro
 |          `* Re: "Usability" (was Re: Map iteration and modification)Randy Brukardt
 |           +- Re: "Usability" (was Re: Map iteration and modification)Niklas Holsti
 |           +- Re: "Usability" (was Re: Map iteration and modification)Lawrence D'Oliveiro
 |           `* Re: "Usability" (was Re: Map iteration and modification)J-P. Rosen
 |            +- Re: "Usability" (was Re: Map iteration and modification)Bill Findlay
 |            `- Re: "Usability" (was Re: Map iteration and modification)Lawrence D'Oliveiro
 `* Re: Map iteration and modificationRandy Brukardt
  `* Re: Map iteration and modificationDrPi
   `* Re: Map iteration and modificationRandy Brukardt
    `- Re: Map iteration and modificationDrPi

Pages:12
Map iteration and modification

<umjukd$9sp$1@rasp.pasdenom.info>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10329&group=comp.lang.ada#10329

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!paganini.bofh.team!pasdenom.info!.POSTED.2a01:e0a:472:70f0:489f:9b4f:758a:47b3!not-for-mail
From: 314@drpi.fr (DrPi)
Newsgroups: comp.lang.ada
Subject: Map iteration and modification
Date: Thu, 28 Dec 2023 14:53:16 +0100
Organization: <http://pasdenom.info/news.html>
Message-ID: <umjukd$9sp$1@rasp.pasdenom.info>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 28 Dec 2023 13:53:17 -0000 (UTC)
Injection-Info: rasp.pasdenom.info; posting-account="314@usenet"; posting-host="2a01:e0a:472:70f0:489f:9b4f:758a:47b3";
logging-data="10137"; mail-complaints-to="abuse@pasdenom.info"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:t3tVRSIex67V4mnxyF0l0qg0bjs= sha256:kIs6qjhAWyT+tR/YICSmOhyp7uvu7O7I9VSyOz+7YVk=
sha1:V9tFAon6DcBaYRdAhxnR3xKE518= sha256:Xp3XlmKOKbLzJsm5I+DyYeoRGGp3c4h56kKy6gYmViA=
Content-Language: fr, en-US
 by: DrPi - Thu, 28 Dec 2023 13:53 UTC

Hi,

I need to delete nodes from a Hashed_Map. I don't know which nodes to
delete in advance. I have to iterate on the Map keys and delete the
nodes which fulfill a condition.
From the LRM I understand I can't delete nodes within a loop iterating
the Map nodes. That makes sense.
What's the recommended way of doing this ?
Iterate the Map and temporarily store the key nodes to be deleted then
delete the nodes from the key list ?

Nicolas

Re: Map iteration and modification

<umjuvc$9sp$2@rasp.pasdenom.info>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10330&group=comp.lang.ada#10330

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!paganini.bofh.team!pasdenom.info!.POSTED.2a01:e0a:472:70f0:489f:9b4f:758a:47b3!not-for-mail
From: 314@drpi.fr (DrPi)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Thu, 28 Dec 2023 14:59:07 +0100
Organization: <http://pasdenom.info/news.html>
Message-ID: <umjuvc$9sp$2@rasp.pasdenom.info>
References: <umjukd$9sp$1@rasp.pasdenom.info>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 28 Dec 2023 13:59:08 -0000 (UTC)
Injection-Info: rasp.pasdenom.info; posting-account="314@usenet"; posting-host="2a01:e0a:472:70f0:489f:9b4f:758a:47b3";
logging-data="10137"; mail-complaints-to="abuse@pasdenom.info"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:4EnUX489pNjLAkD/HAmyz5Bss+A= sha256:IF/q6+BznC2B0GzIn4El4jRs0Pqpm3f0zISvgAHMRqE=
sha1:ce73oxzr3UUedjkRsKGaWMp/bpE= sha256:j7fPPcFoQ54nfdYQO+i6Wex/5BnBVFIIDW1p9HKPBtI=
Content-Language: fr, en-US
In-Reply-To: <umjukd$9sp$1@rasp.pasdenom.info>
 by: DrPi - Thu, 28 Dec 2023 13:59 UTC

Le 28/12/2023 à 14:53, DrPi a écrit :
> Iterate the Map and temporarily store the key nodes to be deleted then
> delete the nodes from the key list ?

Not clear. Rephrasing it.
Using 2 steps by iterating the Map and temporarily store the keys of
nodes to be deleted then delete the Map nodes using the key list ?

Re: Map iteration and modification

<umk6ds$e9hc$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10331&group=comp.lang.ada#10331

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Thu, 28 Dec 2023 17:06:20 +0100
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <umk6ds$e9hc$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info>
<umjuvc$9sp$2@rasp.pasdenom.info>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 28 Dec 2023 16:06:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="5f5a904f70e875604898357a1c1025d4";
logging-data="468524"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+6jbTyajd7/aUdYxv34Fj4cJbxVBwv18="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ZXACGNQupSc3Y2Qet4XhCDWaGmk=
In-Reply-To: <umjuvc$9sp$2@rasp.pasdenom.info>
Content-Language: en-US
 by: Dmitry A. Kazakov - Thu, 28 Dec 2023 16:06 UTC

On 2023-12-28 14:59, DrPi wrote:
> Le 28/12/2023 à 14:53, DrPi a écrit :
>> Iterate the Map and temporarily store the key nodes to be deleted then
>> delete the nodes from the key list ?
>
> Not clear. Rephrasing it.
> Using 2 steps by iterating the Map and temporarily store the keys of
> nodes to be deleted then delete the Map nodes using the key list ?

[Disclaimer. I am not talking about the standard library]

Provided a sane implementation of map.

1. It is safe to loop over the map items in the *reverse* order of,
deleting whatever items.

2. It is safe to walk whatever set of map keys, deleting items of the map.

In both cases #1 positions, #2 keys are invariant to the operation of
deletion.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Map iteration and modification

<umkcud$59g$1@rasp.pasdenom.info>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10332&group=comp.lang.ada#10332

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!paganini.bofh.team!pasdenom.info!.POSTED.2a01:e0a:472:70f0:489f:9b4f:758a:47b3!not-for-mail
From: 314@drpi.fr (DrPi)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Thu, 28 Dec 2023 18:57:32 +0100
Organization: <http://pasdenom.info/news.html>
Message-ID: <umkcud$59g$1@rasp.pasdenom.info>
References: <umjukd$9sp$1@rasp.pasdenom.info>
<umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 28 Dec 2023 17:57:33 -0000 (UTC)
Injection-Info: rasp.pasdenom.info; posting-account="314@usenet"; posting-host="2a01:e0a:472:70f0:489f:9b4f:758a:47b3";
logging-data="5424"; mail-complaints-to="abuse@pasdenom.info"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:PAoutSDeupJPI+cl0LcaLLOW0Ec= sha256:KvdJ/gLmwA8/RWeIL+myo9cAmDXTRW3YywjbbtEB3E4=
sha1:4J6vPWRv079i/WEohrH0GYLgdBY= sha256:TLiOJDMXxOfF3EPIL7dHH/FoLm8Ellr8SnTrThRxowA=
Content-Language: fr
In-Reply-To: <umk6ds$e9hc$1@dont-email.me>
 by: DrPi - Thu, 28 Dec 2023 17:57 UTC

Le 28/12/2023 à 17:06, Dmitry A. Kazakov a écrit :
> On 2023-12-28 14:59, DrPi wrote:
>> Le 28/12/2023 à 14:53, DrPi a écrit :
>>> Iterate the Map and temporarily store the key nodes to be deleted
>>> then delete the nodes from the key list ?
>>
>> Not clear. Rephrasing it.
>> Using 2 steps by iterating the Map and temporarily store the keys of
>> nodes to be deleted then delete the Map nodes using the key list ?
>
> [Disclaimer. I am not talking about the standard library]

I'm using the standard library ;)

>
> Provided a sane implementation of map.
>
> 1. It is safe to loop over the map items in the *reverse* order of,
> deleting whatever items.
>
> 2. It is safe to walk whatever set of map keys, deleting items of the map.
>
> In both cases #1 positions, #2 keys are invariant to the operation of
> deletion.
>

Re: Map iteration and modification

<umld63$n81g$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10334&group=comp.lang.ada#10334

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Thu, 28 Dec 2023 21:08:47 -0600
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <umld63$n81g$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info> <umjuvc$9sp$2@rasp.pasdenom.info>
Injection-Date: Fri, 29 Dec 2023 03:07:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="fc28b7e71a37236b148ceb2dd7a88638";
logging-data="761904"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BW2aQLLJZOlGxixkq88RTWI8/wxTFyOM="
Cancel-Lock: sha1:ybCOePuFB0jJkhYXmqjkVbmKJcI=
X-MSMail-Priority: Normal
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-Priority: 3
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
 by: Randy Brukardt - Fri, 29 Dec 2023 03:08 UTC

"DrPi" <314@drpi.fr> wrote in message
news:umjuvc$9sp$2@rasp.pasdenom.info...
> Le 28/12/2023 � 14:53, DrPi a �crit :
>> Iterate the Map and temporarily store the key nodes to be deleted then
>> delete the nodes from the key list ?
>
> Not clear. Rephrasing it.
> Using 2 steps by iterating the Map and temporarily store the keys of nodes
> to be deleted then delete the Map nodes using the key list ?

If the keys are messy to save (as say with type String), it might be easier
to save the cursor(s) of the nodes to delete. You would probably want to use
a cursor iterator (that is, "in") to get the cursors. Code would be
something like (declarations of the Map and List not shown, nor is the
function Need_to_Delete which is obviously application specific, Save_List
is a list of cursors for My_Map, everything else is standard, not checked
for syntax errors):

Save_List.Empty; -- Clear list of saved cursors.
-- Find the nodes of My_Map that we don't need.
for C in My_Map.Iterate loop
if Need_to_Delete (My_Map.Element(C)) then
Save_List.Append (C);
-- else no need to do anything.
end if;
end loop;
-- Delete the cursors of the nodes we don't want anymore.
for C of Save_List loop
My_Map.Delete(C);
end loop;

Randy.

Re: Map iteration and modification

<umldsq$na79$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10335&group=comp.lang.ada#10335

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Thu, 28 Dec 2023 21:20:53 -0600
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <umldsq$na79$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info> <umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me>
Injection-Date: Fri, 29 Dec 2023 03:19:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="fc28b7e71a37236b148ceb2dd7a88638";
logging-data="764137"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1RD8QOuBtKXzQpdNiiEdreqkyHqFD2AM="
Cancel-Lock: sha1:kBBrioNm4DD4BmQjrntQmWWElK8=
X-RFC2646: Format=Flowed; Response
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-Priority: 3
 by: Randy Brukardt - Fri, 29 Dec 2023 03:20 UTC

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:umk6ds$e9hc$1@dont-email.me...
....
> Provided a sane implementation of map.
>
> 1. It is safe to loop over the map items in the *reverse* order of,
> deleting whatever items.

A sane implementation of a map does not have/require an ordering of keys. So
the idea of "reverse" or "forward" does not make sense for a general map.
(There are, of course, special cases where the keys have an order that
matters to the map; the standard ordered map is like that.) Assuming an
ordering is exposing the implementation unnecessarily.

You always complain about mixing implementation with interface, but you are
clearly doing that here. That technique really only works if the data
structure is implemented with an underlying array. If you have separately
allocated nodes, deletion might completely destroy a node that the iterator
is holding onto. Avoiding that takes significant efforts that sap
performance when you don't intend to modify the container you're iterating
(which is the usual case).

My longstanding objection to the entire concept of arrays is that they are
not a data structure, but rather a building block for making data
structures. One wants indexed sequences sometimes, cheap maps othertimes,
but arrays have all of the operations needed for both, along with other
capabilities not really related to data structures at all. It's way better
to declare what you need and get no more (visibly, at least). That makes it
way easier to swap implementations if that becomes necessary - you're not
stuck with a large array that really should be managed piecemeal.

Randy.

Re: Map iteration and modification

<umm4r5$ppag$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10336&group=comp.lang.ada#10336

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Fri, 29 Dec 2023 10:51:33 +0100
Organization: A noiseless patient Spider
Lines: 104
Message-ID: <umm4r5$ppag$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info>
<umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me>
<umldsq$na79$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 29 Dec 2023 09:51:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="311365a112cb887017aa9196999f4eee";
logging-data="845136"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9+dAV7xHZejL8SUJ2w5jstVYMnT70/BU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:W10kgCBvHPImWemifxVZiettXMc=
Content-Language: en-US
In-Reply-To: <umldsq$na79$1@dont-email.me>
 by: Dmitry A. Kazakov - Fri, 29 Dec 2023 09:51 UTC

On 2023-12-29 04:20, Randy Brukardt wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:umk6ds$e9hc$1@dont-email.me...
> ...
>> Provided a sane implementation of map.
>>
>> 1. It is safe to loop over the map items in the *reverse* order of,
>> deleting whatever items.
>
> A sane implementation of a map does not have/require an ordering of keys.

Yes, but iterating a map requires ordering regardless properties of the
keys.

> So
> the idea of "reverse" or "forward" does not make sense for a general map.
> (There are, of course, special cases where the keys have an order that
> matters to the map; the standard ordered map is like that.) Assuming an
> ordering is exposing the implementation unnecessarily.

It always does sense *IF* enumeration (needed for iteration) is
provided. Enumeration of pairs (<key>, <value>) is not same as ordering
values by the keys.

> You always complain about mixing implementation with interface, but you are
> clearly doing that here. That technique really only works if the data
> structure is implemented with an underlying array. If you have separately
> allocated nodes, deletion might completely destroy a node that the iterator
> is holding onto. Avoiding that takes significant efforts that sap
> performance when you don't intend to modify the container you're iterating
> (which is the usual case).

No. First, it is two different interfaces. A view of a map as:

1. An ordered set of pairs (<key>, <value>)

2. A mapping <key> -> <value>

Second, the point is that both are array interfaces. The first has
position as the index, the second has the key as the index.

Both are invariant to removal a pair and any *sane* implementation must
be OK with that.

The problem is not whether you allocate pairs individually or not. The
insanity begins with things unrelated to the map:

1. OOP iterator object.

2. FP iteration function.

Both are bad ideas imposed by poor programming paradigms on
implementation of a clear mathematical concept. That comes with
constraints, assumptions and limitation array interface do not have.

for Index in reverse Map'Range loop
Map.Delete (Index);
end loop;

would always work. OOP/FP anti-patterns, who knows?

> My longstanding objection to the entire concept of arrays is that they are
> not a data structure, but rather a building block for making data
> structures.

Arrays have interface and implementation. The array interface is a
mapping key -> value, the most fundamental thing in programming. An
array implementation as a contiguous block of values indexed by a linear
function is a basic data structure that supports the interface.

> One wants indexed sequences sometimes, cheap maps othertimes,
> but arrays have all of the operations needed for both, along with other
> capabilities not really related to data structures at all.

Let me help (:-))

One wants array interface without a built-in array implementation.

> It's way better
> to declare what you need and get no more (visibly, at least). That makes it
> way easier to swap implementations if that becomes necessary - you're not
> stuck with a large array that really should be managed piecemeal.

Sure. The problem with Ada is that it does not separate array interface
from its built-in array implementation and does not separate record
interface and implementation either.

Both are mappings. BTW in many cases people could prefer record
interface of a map to array interface:

Map.Key

instead of

Map (Key)

Now, tell me that you have a longstanding objection to the entire
concept of records... (:-))

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Map iteration and modification

<ummj1i$e64$1@rasp.pasdenom.info>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10337&group=comp.lang.ada#10337

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!paganini.bofh.team!pasdenom.info!.POSTED.famillepinault.fr!not-for-mail
From: 314@drpi.fr (DrPi)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Fri, 29 Dec 2023 14:53:53 +0100
Organization: <http://pasdenom.info/news.html>
Message-ID: <ummj1i$e64$1@rasp.pasdenom.info>
References: <umjukd$9sp$1@rasp.pasdenom.info>
<umjuvc$9sp$2@rasp.pasdenom.info> <umld63$n81g$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Dec 2023 13:53:54 -0000 (UTC)
Injection-Info: rasp.pasdenom.info; posting-account="314@usenet"; posting-host="famillepinault.fr:82.65.30.55";
logging-data="14532"; mail-complaints-to="abuse@pasdenom.info"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:rRpS2DQ2mwc0rjmkUyNZyHRk9JY= sha256:gy+i7qNo0rmBw4gr8fxDZucF8vu/f/zsDpBjtGvy4xo=
sha1:2/iiQKjCpj4D0eqlgQ7lE/5BZ7Y= sha256:4BlA0MZykKvWvhmFML5OYTVyXiVKwQrIqXiY4Jeipdw=
In-Reply-To: <umld63$n81g$1@dont-email.me>
Content-Language: fr
 by: DrPi - Fri, 29 Dec 2023 13:53 UTC

Le 29/12/2023 à 04:08, Randy Brukardt a écrit :
> "DrPi" <314@drpi.fr> wrote in message
> news:umjuvc$9sp$2@rasp.pasdenom.info...
>> Le 28/12/2023 à 14:53, DrPi a écrit :
>>> Iterate the Map and temporarily store the key nodes to be deleted then
>>> delete the nodes from the key list ?
>>
>> Not clear. Rephrasing it.
>> Using 2 steps by iterating the Map and temporarily store the keys of nodes
>> to be deleted then delete the Map nodes using the key list ?
>
> If the keys are messy to save (as say with type String), it might be easier
> to save the cursor(s) of the nodes to delete. You would probably want to use
> a cursor iterator (that is, "in") to get the cursors. Code would be
> something like (declarations of the Map and List not shown, nor is the
> function Need_to_Delete which is obviously application specific, Save_List
> is a list of cursors for My_Map, everything else is standard, not checked
> for syntax errors):
>
> Save_List.Empty; -- Clear list of saved cursors.
> -- Find the nodes of My_Map that we don't need.
> for C in My_Map.Iterate loop
> if Need_to_Delete (My_Map.Element(C)) then
> Save_List.Append (C);
> -- else no need to do anything.
> end if;
> end loop;
> -- Delete the cursors of the nodes we don't want anymore.
> for C of Save_List loop
> My_Map.Delete(C);
> end loop;
>
>
That's what I did but I saved the keys (String) instead of the cursors.
Does it make a difference ? Performance maybe ?

Nicolas
>
> Randy.
>
>

Re: Map iteration and modification

<ummn4v$s6gr$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10338&group=comp.lang.ada#10338

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bauhaus@notmyhomepage.invalid (G.B.)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Fri, 29 Dec 2023 16:03:59 +0100
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <ummn4v$s6gr$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info>
<umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me>
<umldsq$na79$1@dont-email.me> <umm4r5$ppag$1@dont-email.me>
Reply-To: nonlegitur@notmyhomepage.de
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 29 Dec 2023 15:03:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="20d47fb31374ad247ab608a0a34a83f6";
logging-data="924187"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19xOWiDXqQ0oUuHSx4hDvzGQAcoOr4gdbc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:z+zpUdRGNzX6UZ65wjJXtUAZG2w=
In-Reply-To: <umm4r5$ppag$1@dont-email.me>
Content-Language: en-US
 by: G.B. - Fri, 29 Dec 2023 15:03 UTC

On 29.12.23 10:51, Dmitry A. Kazakov wrote:
> On 2023-12-29 04:20, Randy Brukardt wrote:
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>> news:umk6ds$e9hc$1@dont-email.me...
>> ...
>>> Provided a sane implementation of map.
>>>
>>> 1. It is safe to loop over the map items in the *reverse* order of,
>>> deleting whatever items.
>>
>> A sane implementation of a map does not have/require an ordering of keys.
>
> Yes, but iterating a map requires ordering regardless properties of the keys.

Suppose that there is a way of orderly proceeding from one item to the next.
It is probably known to the implementation of map. Do single steps
guarantee transitivity, though, so that an algorithm can assume the
order to be invariable?

At the start of the algorithm, the assumption of order of items implies
an ordered sequence of all the keys. Someone might want to use this known
order for a cache of "index values". It might be the implementation
that does so.

Now some item is removed. The cache is no longer valid...

Insane? Or just tampering? (Randy Brukardt's example demonstrates
the mitigation using Cursor, I think.)

Maybe the bulk operations of some DBMS' programming
interfaces work just like this, for practical reasons.
Ada 202x' Ordered_Maps might want to add a feature ;-)

procedure Delete (Container : in out Map;
From : in out Cursor;
To : in out Cursor);

Re: Map iteration and modification

<ummtfl$t4uo$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10339&group=comp.lang.ada#10339

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Fri, 29 Dec 2023 17:52:07 +0100
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <ummtfl$t4uo$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info>
<umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me>
<umldsq$na79$1@dont-email.me> <umm4r5$ppag$1@dont-email.me>
<ummn4v$s6gr$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Dec 2023 16:52:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="311365a112cb887017aa9196999f4eee";
logging-data="955352"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/LhccrYWjDsndD3Ml+HnXJEi73Kh0J6ks="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Aq+1uAhX56Pvo3keu/97VKXHZHY=
Content-Language: en-US
In-Reply-To: <ummn4v$s6gr$1@dont-email.me>
 by: Dmitry A. Kazakov - Fri, 29 Dec 2023 16:52 UTC

On 2023-12-29 16:03, G.B. wrote:
> On 29.12.23 10:51, Dmitry A. Kazakov wrote:
>> On 2023-12-29 04:20, Randy Brukardt wrote:
>>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>>> news:umk6ds$e9hc$1@dont-email.me...
>>> ...
>>>> Provided a sane implementation of map.
>>>>
>>>> 1. It is safe to loop over the map items in the *reverse* order of,
>>>> deleting whatever items.
>>>
>>> A sane implementation of a map does not have/require an ordering of
>>> keys.
>>
>> Yes, but iterating a map requires ordering regardless properties of
>> the keys.
>
> Suppose that there is a way of orderly proceeding from one item to the
> next.
> It is probably known to the implementation of map. Do single steps
> guarantee transitivity, though, so that an algorithm can assume the
> order to be invariable?

An insane implementation can expose random orders each time.

> At the start of the algorithm, the assumption of order of items implies
> an ordered sequence of all the keys.

You do not need ordered keys to enumerate pairs. For example, consider a
2D array. As a map it has keys (row, column) which are unordered.

> Someone might want to use this known
> order for a cache of "index values". It might be the implementation
> that does so.

If not exposed through an interface the order cannot be known. The
question is whether there must be such interface or not. In my view a
good container library must provide position->pair interface, no OOP's
cursors/iterators and no functional stuff like Foreach.

> Insane? Or just tampering? (Randy Brukardt's example demonstrates
> the mitigation using Cursor, I think.)

Unless removing element invalidates all cursors. Look, insanity has no
bounds. Cursors AKA pointers are as volatile as positions in certain
implementations. Consider a garbage collector running after removing a
pair and shuffling remaining pairs in memory.

> Maybe the bulk operations of some DBMS' programming
> interfaces work just like this, for practical reasons.
> Ada 202x' Ordered_Maps might want to add a feature ;-)
>
>      procedure Delete (Container : in out Map;
>                        From      : in out Cursor;
>                        To        : in out Cursor);

Here you assume that cursors are ordered and the order is preserved from
call to call. Even if From and To are stable the range From..To can
include random pairs in between.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Map iteration and modification

<umoda6$16pk8$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10341&group=comp.lang.ada#10341

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Sat, 30 Dec 2023 00:29:07 -0600
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <umoda6$16pk8$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info> <umjuvc$9sp$2@rasp.pasdenom.info> <umld63$n81g$1@dont-email.me> <ummj1i$e64$1@rasp.pasdenom.info>
Injection-Date: Sat, 30 Dec 2023 06:28:23 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2d85733152c498363b0c58151a247659";
logging-data="1271432"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1ylOjwsd3+GppSdj5Z3h49k6NVlKw96s="
Cancel-Lock: sha1:fWTvuYGa9jF1T4X1Rj40A220+mo=
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-RFC2646: Format=Flowed; Response
X-Priority: 3
X-MSMail-Priority: Normal
 by: Randy Brukardt - Sat, 30 Dec 2023 06:29 UTC

"DrPi" <314@drpi.fr> wrote in message
news:ummj1i$e64$1@rasp.pasdenom.info...
.... (Example eliminated)

> That's what I did but I saved the keys (String) instead of the cursors.
> Does it make a difference ? Performance maybe ?

It certainly will make a performance difference; whether that difference is
significant of course depends on the implementation. There's two parts to it
(one of which I thought of yesterday and the other which I forgot):
(1) The cost of storing keys vs. storing cursors. Cursors are going to be
implemented as small record types (cannonically, they are two pointers, one
to the enclosing container and one to the specific node/element). A key can
be most anything, and storing that can be more costly.
(2) The cost of looking up a key. A map is a set of nodes, and there
needs to be some operation to associate a key with the correct node. Those
operations take some time, of course: for a hashed map, the key has to be
hashed and then some sort of lookup performed. Whereas a cursor generally
contains an indication of the node, so the access is more direct.

For a lot of applications, this difference won't matter enough to be
significant. But I'd probably lean toward using cursors for this sort of job
as that would minimize performance problems down the line. (Of course, if
the container gets modified after you save the cursors, then they could
become dangling, which is a problem of it's own. If that's a possibility,
saving the keys is better.)

Randy.

Re: Map iteration and modification

<umogc5$173bb$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10342&group=comp.lang.ada#10342

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Sat, 30 Dec 2023 01:21:22 -0600
Organization: A noiseless patient Spider
Lines: 144
Message-ID: <umogc5$173bb$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info> <umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me> <umldsq$na79$1@dont-email.me> <umm4r5$ppag$1@dont-email.me>
Injection-Date: Sat, 30 Dec 2023 07:20:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2d85733152c498363b0c58151a247659";
logging-data="1281387"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19NChOAyppx6WwFBS20fBTN3Y7kKNQNtYY="
Cancel-Lock: sha1://AITMHGILA8z6BkpxGHg55RDtQ=
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-Priority: 3
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-MSMail-Priority: Normal
 by: Randy Brukardt - Sat, 30 Dec 2023 07:21 UTC

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:umm4r5$ppag$1@dont-email.me...
> On 2023-12-29 04:20, Randy Brukardt wrote:
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>> news:umk6ds$e9hc$1@dont-email.me...
>> ...
>>> Provided a sane implementation of map.
>>>
>>> 1. It is safe to loop over the map items in the *reverse* order of,
>>> deleting whatever items.
>>
>> A sane implementation of a map does not have/require an ordering of keys.
>
> Yes, but iterating a map requires ordering regardless properties of the
> keys.

Only as far as there is an order implied by the order that things are
returned. That order doesn't have any meaning, and certainly there isn't any
such thing as "forward" or "reverse" to it. (Which was the original claim,
after all.) There is no "natural" order to the key/element pairs; they are
effectively unordered.

....

>> So
>> the idea of "reverse" or "forward" does not make sense for a general map.
>> (There are, of course, special cases where the keys have an order that
>> matters to the map; the standard ordered map is like that.) Assuming an
>> ordering is exposing the implementation unnecessarily.
>
> It always does sense *IF* enumeration (needed for iteration) is provided.
> Enumeration of pairs (<key>, <value>) is not same as ordering values by
> the keys.

True, but it doesn't imply any particular ordering. Certainly, no concept of
"forward" or "reverse" applies to such an ordering (nor any stability
requirement). Practically, you'll get the same order each time if the
container isn't modified, but if it is, all bets are off. (If the container
is changed by element addition or deletion, the index may get rebuilt [hash
table reconstructed if too full, tree-index rebalanced, etc.] and that can
change the iteration order dramatically.)

....
> No. First, it is two different interfaces. A view of a map as:
>
> 1. An ordered set of pairs (<key>, <value>)

This is not a map (in general). There is an *unordered* set of pairs. You
can retrieve them all, but the order that is done is meaningless and is an
artifact of the implementation. There's a reason that maps don't have
reverse iterators.

> 2. A mapping <key> -> <value>
>
> Second, the point is that both are array interfaces. The first has
> position as the index, the second has the key as the index.

"Position" is not a property of an (abstract) map. That's my complaint about
looking at everything as an array -- one starts thinking in terms of
properties that things don't have (or need).

> Both are invariant to removal a pair and any *sane* implementation must be
> OK with that.

The only sort of position that you could possibility talk about for a map is
the ordinal order that an iterator returns key/element pairs. But that
necessarily changes when you insert/delete a pair, as that pair will occur
at some (unspecified) point in the ordinal order. Otherwise, you won't have
the performance expected for key lookup in a map.

> The problem is not whether you allocate pairs individually or not. The
> insanity begins with things unrelated to the map:
>
> 1. OOP iterator object.
>
> 2. FP iteration function.
>
> Both are bad ideas imposed by poor programming paradigms on implementation
> of a clear mathematical concept. That comes with constraints, assumptions
> and limitation array interface do not have.

??? Abstractions are "poor ideas"? You have some problem with an iterator
interface as opposed to an array interface?? That make no sense at all given
your other positions.

> for Index in reverse Map'Range loop
> Map.Delete (Index);
> end loop;
>
> would always work.

It only works if you think of Map'Range as an iterator object. Otherwise,
you would have to impose an extra "position" interface on the map (or other
container), and at a substantial additional cost in time/space. Containers
in general don't have "positions", elements are unordered unless the
container imposes one.

....
> Arrays have interface and implementation. The array interface is a mapping
> key -> value, the most fundamental thing in programming.

That's only part of it. It also includes the idea of "position", including
calculated positions, the operations of concatenation and slicing, and (for
Ada at least) ordering operations. If the array interface was *only* a
mapping I would not object to it. Maps do not have a natural order, and
nothing should be depending on such order. There is no meaning to the third
pair in a map.

> An array implementation as a contiguous block of values indexed by a
> linear function is a basic data structure that supports the interface.

Right: the much more complex interface I note above. And that's the problem.
You don't even seem to realize all of the unnecessary baggage that arrays
carry with them.

....
> Sure. The problem with Ada is that it does not separate array interface
> from its built-in array implementation and does not separate record
> interface and implementation either.

Not arguing this. (Other than this is way down the list of problems with
Ada, there are many that are worse.)

....
> Now, tell me that you have a longstanding objection to the entire concept
> of records... (:-))

Nope. There has to be a hetrogenous grouping of values, and records do it as
well as anything else. I do agree that more abstraction would be nice.

The problem with arrays is that the mapping part is tied to many other
supposedly fundamental capabilities that aren't fundamental at all. Even
intellegent people such as yourself have been using arrays so long and so
primitively that you've gotten blinded to the fact that basic data
structures really have only a handful of operations, and the majority of the
"fundamental" capabilities aren't needed much of the time and certainly
should only be provided when needed.

Randy.

Re: Map iteration and modification

<umotm2$18lqm$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10343&group=comp.lang.ada#10343

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Sat, 30 Dec 2023 12:07:47 +0100
Organization: A noiseless patient Spider
Lines: 219
Message-ID: <umotm2$18lqm$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info>
<umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me>
<umldsq$na79$1@dont-email.me> <umm4r5$ppag$1@dont-email.me>
<umogc5$173bb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 30 Dec 2023 11:07:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="4d8b9ba1fd8fe0f2133fc188d94400b6";
logging-data="1333078"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+A65CM209xkJezLYW6uT38rVuoOZUCu1I="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:HOU622htwq5IyP2I/9X1tsHdrHk=
Content-Language: en-US
In-Reply-To: <umogc5$173bb$1@dont-email.me>
 by: Dmitry A. Kazakov - Sat, 30 Dec 2023 11:07 UTC

On 2023-12-30 08:21, Randy Brukardt wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:umm4r5$ppag$1@dont-email.me...
>> On 2023-12-29 04:20, Randy Brukardt wrote:
>>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>>> news:umk6ds$e9hc$1@dont-email.me...
>>> ...
>>>> Provided a sane implementation of map.
>>>>
>>>> 1. It is safe to loop over the map items in the *reverse* order of,
>>>> deleting whatever items.
>>>
>>> A sane implementation of a map does not have/require an ordering of keys.
>>
>> Yes, but iterating a map requires ordering regardless properties of the
>> keys.
>
> Only as far as there is an order implied by the order that things are
> returned. That order doesn't have any meaning, and certainly there isn't any
> such thing as "forward" or "reverse" to it. (Which was the original claim,
> after all.) There is no "natural" order to the key/element pairs; they are
> effectively unordered.

Iteration = order. It is the same thing. If you provide iteration of
pairs in the mapping by doing so you provide an order of.

>> It always does sense *IF* enumeration (needed for iteration) is provided.
>> Enumeration of pairs (<key>, <value>) is not same as ordering values by
>> the keys.
>
> True, but it doesn't imply any particular ordering. Certainly, no concept of
> "forward" or "reverse" applies to such an ordering (nor any stability
> requirement).

It does. You have a strict total order of pairs which guarantees
existence of previous and next pairs according to.

> Practically, you'll get the same order each time if the
> container isn't modified, but if it is, all bets are off. (If the container
> is changed by element addition or deletion, the index may get rebuilt [hash
> table reconstructed if too full, tree-index rebalanced, etc.] and that can
> change the iteration order dramatically.)

True, an operation may invalidate whatever invariants. It applies
equally to any orders, any cursors and pointers, any hidden states of
pending foreach operations. Sanity means which invariants the
implementation keeps.

I would argue that for general-case containers keeping
iterators/pointers and hidden states would be far more difficult than
keeping an order.

>> No. First, it is two different interfaces. A view of a map as:
>>
>> 1. An ordered set of pairs (<key>, <value>)
>
> This is not a map (in general). There is an *unordered* set of pairs. You
> can retrieve them all, but the order that is done is meaningless and is an
> artifact of the implementation. There's a reason that maps don't have
> reverse iterators.

Unless you provide iteration of the map. Most applications want
iteratable maps. Then a finite maps is still iteratable regardless best
efforts, though by crude means. E.g. once have an array (ordered set) of
keys, you are done.

>> 2. A mapping <key> -> <value>
>>
>> Second, the point is that both are array interfaces. The first has
>> position as the index, the second has the key as the index.
>
> "Position" is not a property of an (abstract) map. That's my complaint about
> looking at everything as an array -- one starts thinking in terms of
> properties that things don't have (or need).

Yes position is a property of enumeration.

>> Both are invariant to removal a pair and any *sane* implementation must be
>> OK with that.
>
> The only sort of position that you could possibility talk about for a map is
> the ordinal order that an iterator returns key/element pairs.

It is the reverse. Iterators is secondary to the order. Iterator walks
pairs in the order of pairs = in the order their positions.

> But that
> necessarily changes when you insert/delete a pair, as that pair will occur
> at some (unspecified) point in the ordinal order. Otherwise, you won't have
> the performance expected for key lookup in a map.

If you provide a random order, then yes. This is what an "insane"
implementation would do. A "sane" implementation would deploy orders
with reasonable properties. E.g. an obvious: k1/=k2/=k3 then (k1,v1) <
(k2,v2) is preserved when (k3,v3) is added or removed.

>> The problem is not whether you allocate pairs individually or not. The
>> insanity begins with things unrelated to the map:
>>
>> 1. OOP iterator object.
>>
>> 2. FP iteration function.
>>
>> Both are bad ideas imposed by poor programming paradigms on implementation
>> of a clear mathematical concept. That comes with constraints, assumptions
>> and limitation array interface do not have.
>
> ??? Abstractions are "poor ideas"?

Neither is an abstraction [as they are not entities of the problem
space, but programming techniques artifacts, [anti-]patterns]. Iterator
is an object of an unrelated type. Foreach is a stateful operation
unrelated to the pure map interface.

> You have some problem with an iterator
> interface as opposed to an array interface??

Yes, I am against pointers (referential semantics) in general. BTW, Ada
should have abstract pointer interface allowing the programmer to
implement iterators = fat pointers.

[ It would be fun with the pure unordered maps you suggested, the
implementation of the pointer (iterator) would keep an array or an
ordered set of keys... (:-)) ]

>> for Index in reverse Map'Range loop
>> Map.Delete (Index);
>> end loop;
>>
>> would always work.
>
> It only works if you think of Map'Range as an iterator object. Otherwise,
> you would have to impose an extra "position" interface on the map (or other
> container), and at a substantial additional cost in time/space. Containers
> in general don't have "positions", elements are unordered unless the
> container imposes one.

Yes, I would impose positions in all general case containers.

Specialized very large containers where an implementation without
cashing would become O(log n) rather than O(1) deploy other means of
traversal anyway.

>> Arrays have interface and implementation. The array interface is a mapping
>> key -> value, the most fundamental thing in programming.
>
> That's only part of it. It also includes the idea of "position",

Yes. Position in array is a mapping key/index <-> Natural.

> including calculated positions,

Yes. Natural numbers have numeric operations.

> the operations of concatenation and slicing,

That depends, but like with maps, it is expected. Maps as containers are
expected to provide "concatenations" of pairs (set-theoretic union) and
slicing (submaps). Because mathematically maps are sets of pairs and
sets can be manipulated in many ways. Ordering does not add much to the
interface.

> and (for
> Ada at least) ordering operations. If the array interface was *only* a
> mapping I would not object to it. Maps do not have a natural order, and
> nothing should be depending on such order. There is no meaning to the third
> pair in a map.

Yes, but those are not iteratable. We are talking about maps one can
iterate. That requires an order. The question is only about the forms of
exposure of that order in the interface. My objection is that iterators
and foreach are poor forms.

>> An array implementation as a contiguous block of values indexed by a
>> linear function is a basic data structure that supports the interface.
>
> Right: the much more complex interface I note above. And that's the problem.
> You don't even seem to realize all of the unnecessary baggage that arrays
> carry with them.

I don't see anything that is not already there. What are reasons for not
providing:

M (n) [ e.g. M (n).Key, M (n).Value ]
M (n1..n2) [ in mutable contexts too ]
M'First
M'Last
M1 & M2 [ M1 or M2 ]

They are all well-defined and useful operations.

> The problem with arrays is that the mapping part is tied to many other
> supposedly fundamental capabilities that aren't fundamental at all.

I disagree in the case of 1D arrays. There is of course interesting
issues with nD arrays but that is where multiple inheritance kicks in,
because in mathematics you can have "continuations" of concepts in more
than one direction. So 1D array might be both an nD array and something
else too.

> Even
> intellegent people such as yourself have been using arrays so long and so
> primitively that you've gotten blinded to the fact that basic data
> structures really have only a handful of operations, and the majority of the
> "fundamental" capabilities aren't needed much of the time and certainly
> should only be provided when needed.


Click here to read the complete article
Re: Map iteration and modification

<umrrtn$pps$1@rasp.pasdenom.info>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10344&group=comp.lang.ada#10344

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.niel.me!pasdenom.info!.POSTED.2a01:e0a:472:70f0:a9b2:5554:1dc8:f27e!not-for-mail
From: 314@drpi.fr (DrPi)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Sun, 31 Dec 2023 14:56:05 +0100
Organization: <http://pasdenom.info/news.html>
Message-ID: <umrrtn$pps$1@rasp.pasdenom.info>
References: <umjukd$9sp$1@rasp.pasdenom.info>
<umjuvc$9sp$2@rasp.pasdenom.info> <umld63$n81g$1@dont-email.me>
<ummj1i$e64$1@rasp.pasdenom.info> <umoda6$16pk8$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 31 Dec 2023 13:56:07 -0000 (UTC)
Injection-Info: rasp.pasdenom.info; posting-account="314@usenet"; posting-host="2a01:e0a:472:70f0:a9b2:5554:1dc8:f27e";
logging-data="26428"; mail-complaints-to="abuse@pasdenom.info"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:basbfb0LpUfoiScA/js2E6NMKFg= sha256:FfNUFwTgb8JXg6HEq+ufLvQXuag0foGi4voS7Gjpq9c=
sha1:9LrzZbCaUrL6oV88GwPWfFkGPd8= sha256:FQAjFT3anISrRmB1AH8HpCXLcRWGBCoNLKkpLifLsp8=
In-Reply-To: <umoda6$16pk8$1@dont-email.me>
Content-Language: fr
 by: DrPi - Sun, 31 Dec 2023 13:56 UTC

Le 30/12/2023 à 07:29, Randy Brukardt a écrit :
> "DrPi" <314@drpi.fr> wrote in message
> news:ummj1i$e64$1@rasp.pasdenom.info...
> ... (Example eliminated)
>
>> That's what I did but I saved the keys (String) instead of the cursors.
>> Does it make a difference ? Performance maybe ?
>
> It certainly will make a performance difference; whether that difference is
> significant of course depends on the implementation. There's two parts to it
> (one of which I thought of yesterday and the other which I forgot):
> (1) The cost of storing keys vs. storing cursors. Cursors are going to be
> implemented as small record types (cannonically, they are two pointers, one
> to the enclosing container and one to the specific node/element). A key can
> be most anything, and storing that can be more costly.
> (2) The cost of looking up a key. A map is a set of nodes, and there
> needs to be some operation to associate a key with the correct node. Those
> operations take some time, of course: for a hashed map, the key has to be
> hashed and then some sort of lookup performed. Whereas a cursor generally
> contains an indication of the node, so the access is more direct.
>
> For a lot of applications, this difference won't matter enough to be
> significant. But I'd probably lean toward using cursors for this sort of job
> as that would minimize performance problems down the line. (Of course, if
> the container gets modified after you save the cursors, then they could
> become dangling, which is a problem of it's own. If that's a possibility,
> saving the keys is better.)
>
I modified my code to use cursors.
Thanks for your help.

Nicolas

Re: Map iteration and modification

<umv3nn$2adp0$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10345&group=comp.lang.ada#10345

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bauhaus@notmyhomepage.invalid (G.B.)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Mon, 1 Jan 2024 20:27:51 +0100
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <umv3nn$2adp0$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info>
<umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me>
<umldsq$na79$1@dont-email.me> <umm4r5$ppag$1@dont-email.me>
<ummn4v$s6gr$1@dont-email.me> <ummtfl$t4uo$1@dont-email.me>
Reply-To: nonlegitur@notmyhomepage.de
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 1 Jan 2024 19:27:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3eb352a508ae871bcc96e772bf130991";
logging-data="2438944"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NdugzlngHAkh0lcHNVkLVSjMTf1weYBU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:JntLBwpd72NPisn7osWmv3sutUQ=
In-Reply-To: <ummtfl$t4uo$1@dont-email.me>
Content-Language: en-US
 by: G.B. - Mon, 1 Jan 2024 19:27 UTC

On 29.12.23 17:52, Dmitry A. Kazakov wrote:

>> Suppose that there is a way of orderly proceeding from one item to the next.
>> It is probably known to the implementation of map. Do single steps
>> guarantee transitivity, though, so that an algorithm can assume the
>> order to be invariable?
>
> An insane implementation can expose random orders each time.

An implementation order should then not be exposed, right?
What portable benefits would there be when another interface
is added to that of map, i.e., to Ada containers for general use?
Would it not be possible to get these benefits using a different
approach? I think the use case is clearly stated:

First, find Cursors in map =: C*.
Right after that, Delete from map all nodes referred to by C*.

> Unless removing element invalidates all cursors. Look, insanity has no bounds. Cursors AKA pointers are as volatile as positions in certain implementations. Consider a garbage collector running after removing a pair and shuffling remaining pairs in memory.
>
>> Maybe the bulk operations of some DBMS' programming
>> interfaces work just like this, for practical reasons.
>> Ada 202x' Ordered_Maps might want to add a feature ;-)
>>
>>       procedure Delete (Container : in out Map;
>>                         From      : in out Cursor;
>>                         To        : in out Cursor);
>
> Here you assume that cursors are ordered and the order is preserved from call to call. Even if From and To are stable the range From..To can include random pairs in between.

Yes, given the descriptions of Ordered_Maps, so long as there is no
tampering, a Cursor will respect an order. Likely the one that the
programmer has in mind.

For deleting, this thread has shown a loop that calls Delete
multiple times right after collecting the cursors.
And it is boilerplate text. Could Maps be improved for this use case?

[Bulk deletion] We do get bulk insertion in containers. Also,
A.18.2 already has bulk Delete operations. Similarly,
the Strings packages have them.

[No thread safety needed] If standard Ada maps are usually operated
by just one task, stability of Cursors is predictable.

Then, with or without automatic management of storage,
when My_Map is from an instance of Ordered_Map,

Start := In_13th_Floor (My_Map.Ceiling (13.0));
Finish := In_13th_Floor (My_Map.Floor (Fxd'Pred (14.0)));
My_Map.Delete (
From => Start,
Through => Finish);

where
function In_13th_Floor (C : Cursor) return Cursor
-- C, if the key at C is in [13.0, 14.0), No_Element otherwise

should therefore do the right thing, in that nothing
is left to chance.

Re: Map iteration and modification

<umv8rg$2b4on$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10346&group=comp.lang.ada#10346

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Mon, 1 Jan 2024 21:55:12 +0100
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <umv8rg$2b4on$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info>
<umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me>
<umldsq$na79$1@dont-email.me> <umm4r5$ppag$1@dont-email.me>
<ummn4v$s6gr$1@dont-email.me> <ummtfl$t4uo$1@dont-email.me>
<umv3nn$2adp0$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 1 Jan 2024 20:55:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="910c87df5db3b8fa556d1a1abd71f156";
logging-data="2462487"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18uzGVvyEdCF0Fy07+VbNhORvhjrQU9tms="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:3PyFHBS4Dzxw7f3WqQtoKabFC/Q=
Content-Language: en-US
In-Reply-To: <umv3nn$2adp0$1@dont-email.me>
 by: Dmitry A. Kazakov - Mon, 1 Jan 2024 20:55 UTC

On 2024-01-01 20:27, G.B. wrote:
> On 29.12.23 17:52, Dmitry A. Kazakov wrote:
>
>>> Suppose that there is a way of orderly proceeding from one item to
>>> the next.
>>> It is probably known to the implementation of map. Do single steps
>>> guarantee transitivity, though, so that an algorithm can assume the
>>> order to be invariable?
>>
>> An insane implementation can expose random orders each time.
>
> An implementation order should then not be exposed, right?

IMO, an order should be exposed. Not necessarily the "implementation
order" whatever that might mean.

> What portable benefits would there be when another interface
> is added to that of map, i.e., to Ada containers for general use?

It is same benefit Ada arrays have over C's T* pointers and arithmetic
of. Cursor is merely a fat pointer.

> Would it not be possible to get these benefits using a different
> approach? I think the use case is clearly stated:
>
> First, find Cursors in map =: C*.
> Right after that, Delete from map all nodes referred to by C*.

Right. Find cursors, store cursors in another container, iterate that
container deleting elements of the first. Now, consider that the cursors
in the second container become invalid (dangling pointers). If you
wanted to delete them immediately from the second container, you would
return the square one! (:-))

With a positional access interface it would be just (pure Ada 95):

for Index in reverse 1..Number_Of_Elements (Container) loop
if Want_To_Delete (Get (Container (Index))) then
Delete (Container, Index);
end if;
end loop;

> For deleting, this thread has shown a loop that calls Delete
> multiple times right after collecting the cursors.
> And it is boilerplate text.  Could Maps be improved for this use case?

See above.

> [Bulk deletion] We do get bulk insertion in containers.  Also,
> A.18.2 already has bulk Delete operations.  Similarly,
> the Strings packages have them.
>
> [No thread safety needed] If standard Ada maps are usually operated
> by just one task, stability of Cursors is predictable.
>
> Then, with or without automatic management of storage,
> when My_Map is from an instance of Ordered_Map,
>
>    Start  := In_13th_Floor (My_Map.Ceiling (13.0));
>    Finish := In_13th_Floor (My_Map.Floor (Fxd'Pred (14.0)));
>    My_Map.Delete (
>       From    => Start,
>       Through => Finish);

The case is more general: delete pairs satisfying certain criterion.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Map iteration and modification

<un1e96$2p2av$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10347&group=comp.lang.ada#10347

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bauhaus@notmyhomepage.invalid (G.B.)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Tue, 2 Jan 2024 17:40:06 +0100
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <un1e96$2p2av$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info>
<umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me>
<umldsq$na79$1@dont-email.me> <umm4r5$ppag$1@dont-email.me>
<ummn4v$s6gr$1@dont-email.me> <ummtfl$t4uo$1@dont-email.me>
<umv3nn$2adp0$1@dont-email.me> <umv8rg$2b4on$1@dont-email.me>
Reply-To: nonlegitur@notmyhomepage.de
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 2 Jan 2024 16:40:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="95a70fd134f63a152e8b4dbf5dadc299";
logging-data="2918751"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2Bjia2dvTw0gtCC5PC2kxAZlhIVWhJ/s="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:aA6xGZFh8+YPYs27EgJwOXNlWlM=
In-Reply-To: <umv8rg$2b4on$1@dont-email.me>
Content-Language: en-US
 by: G.B. - Tue, 2 Jan 2024 16:40 UTC

On 01.01.24 21:55, Dmitry A. Kazakov wrote:

>> Would it not be possible to get these benefits using a different
>> approach? I think the use case is clearly stated:
>>
>> First, find Cursors in map =: C*.
>> Right after that, Delete from map all nodes referred to by C*.
>
> Right. Find cursors, store cursors in another container, iterate that container deleting elements of the first. Now, consider that the cursors in the second container become invalid (dangling pointers). If you wanted to delete them immediately from the second container, you would return the square one! (:-))

OK, yet if indicating nodes in a container is designed to survive
any deletions, leaving nothing dangling i.e., doesn't this limit
the way in which implementations can store nodes?
Seems like every "pointer" (= (Container, Position)) needs to know
its element, and/or the container will have to equip its storage
management with a "vacuuming" algorithm accordingly.

Transactions seem more flexible (a locking flag in a sequential
algorithm?), a dedicated operation looks simpler than both.

Re: Map iteration and modification

<un1tbv$2r6uk$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10348&group=comp.lang.ada#10348

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Tue, 2 Jan 2024 21:57:35 +0100
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <un1tbv$2r6uk$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info>
<umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me>
<umldsq$na79$1@dont-email.me> <umm4r5$ppag$1@dont-email.me>
<ummn4v$s6gr$1@dont-email.me> <ummtfl$t4uo$1@dont-email.me>
<umv3nn$2adp0$1@dont-email.me> <umv8rg$2b4on$1@dont-email.me>
<un1e96$2p2av$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 2 Jan 2024 20:57:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="4da79024fa82e70feadccf0f1b74f12b";
logging-data="2989012"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18h7Y4w11iNauwYYyoMqLLDcm89ujzYnpU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:U0L/aPj/YuHVN7W334hfAwL6ee4=
In-Reply-To: <un1e96$2p2av$1@dont-email.me>
Content-Language: en-US
 by: Dmitry A. Kazakov - Tue, 2 Jan 2024 20:57 UTC

On 2024-01-02 17:40, G.B. wrote:
> On 01.01.24 21:55, Dmitry A. Kazakov wrote:
>
>>> Would it not be possible to get these benefits using a different
>>> approach? I think the use case is clearly stated:
>>>
>>> First, find Cursors in map =: C*.
>>> Right after that, Delete from map all nodes referred to by C*.
>>
>> Right. Find cursors, store cursors in another container, iterate that
>> container deleting elements of the first. Now, consider that the
>> cursors in the second container become invalid (dangling pointers). If
>> you wanted to delete them immediately from the second container, you
>> would return the square one! (:-))
>
> OK, yet if indicating nodes in a container is designed to survive
> any deletions, leaving nothing dangling i.e., doesn't this limit
> the way in which implementations can store nodes?

Unless the container keeps references to all pointers and corrects them
as necessary. Which basically defeats the only advantage of pointers.
They have O(1) complexity in large non-contiguous containers while
positions without caching are likely O(log(n)).

> Seems like every "pointer" (= (Container, Position)) needs to know
> its element, and/or the container will have to equip its storage
> management with a "vacuuming" algorithm accordingly.
>
> Transactions seem more flexible (a locking flag in a sequential
> algorithm?), a dedicated operation looks simpler than both.

For large and persistent containers. But that requires a lot of work for
the client and it is slow and resource consuming on the container side.
A general-purpose container must be as simple as tooth powder.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Map iteration and modification

<un2jeb$330jr$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10349&group=comp.lang.ada#10349

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Tue, 2 Jan 2024 21:15:01 -0600
Organization: A noiseless patient Spider
Lines: 120
Message-ID: <un2jeb$330jr$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info> <umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me> <umldsq$na79$1@dont-email.me> <umm4r5$ppag$1@dont-email.me> <umogc5$173bb$1@dont-email.me> <umotm2$18lqm$1@dont-email.me>
Injection-Date: Wed, 3 Jan 2024 03:14:19 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="56dd089a60772e36f9749f23e307c802";
logging-data="3244667"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+c5tMRHTH+tabh8FOGQ8rEXRVEmLlJQBo="
Cancel-Lock: sha1:x5zCH6SmWKAl0hfLiT6VCQqbwJE=
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-Priority: 3
X-RFC2646: Format=Flowed; Response
 by: Randy Brukardt - Wed, 3 Jan 2024 03:15 UTC

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:umotm2$18lqm$1@dont-email.me...
....
>> Only as far as there is an order implied by the order that things are
>> returned. That order doesn't have any meaning, and certainly there isn't
>> any
>> such thing as "forward" or "reverse" to it. (Which was the original
>> claim,
>> after all.) There is no "natural" order to the key/element pairs; they
>> are
>> effectively unordered.
>
> Iteration = order. It is the same thing. If you provide iteration of pairs
> in the mapping by doing so you provide an order of.

Certainly not. An iteration presents all of the elements in a container, but
there is no requirement that there is an order. Indeed, logically, all of
the elements are presented at the same time (and parallel iteration provides
an approximation of that).

If you try to enforce an order on things that don't require it, you end up
preventing useful parallelism (practically, at least, no one has succeeded
at providing useful parallelism to sequential code and people have been
trying for about 50 years -- they were trying when I was a university
student in the late 1970s).

>>> It always does sense *IF* enumeration (needed for iteration) is
>>> provided.
>>> Enumeration of pairs (<key>, <value>) is not same as ordering values by
>>> the keys.
>>
>> True, but it doesn't imply any particular ordering. Certainly, no concept
>> of
>> "forward" or "reverse" applies to such an ordering (nor any stability
>> requirement).
>
> It does. You have a strict total order of pairs which guarantees existence
> of previous and next pairs according to.

Again, this is unrelated. Iteration can usefully occur in unordered
containers (that is, "foreach"). Ordering is a separate concept, not always
needed (certainly not in basic structures like maps, sets, and bags).

....
> True, an operation may invalidate whatever invariants. It applies equally
> to any orders, any cursors and pointers, any hidden states of pending
> foreach operations. Sanity means which invariants the implementation
> keeps.

Ada requires that cursors continue to designate the same element through all
operations other than deletion of the element or movement to a different
container. Specific containers have additional invariants, but this is the
most general one. No other requirement is needed in many cases.

...
>> "Position" is not a property of an (abstract) map. That's my complaint
>> about
>> looking at everything as an array -- one starts thinking in terms of
>> properties that things don't have (or need).
>
> Yes position is a property of enumeration.

Surely not. This is a basis for my disagrement with you here. The only
requirement for enumeration is that all elements are produced. The order is
an artifact of doing it an inherently parallel operation sequentally. We
don't care about or depend on artifacts.

...
> It is the reverse. Iterators is secondary to the order. Iterator walks
> pairs in the order of pairs = in the order their positions.

Nope, this is completely wrong. Once you start with a bogus premise, of
course you will get all kinds of bogus conclusions!!

....
>> You have some problem with an iterator
>> interface as opposed to an array interface??
>
> Yes, I am against pointers (referential semantics) in general.

This is nonsense - virtually everything is referential semantics (other than
components). Array indexes are just a poor mans pointer (indeed, I learned
how to program in Fortran 66 initially, and way one built useful data
structures was to use array indexes as stand-ins for pointers). In A(1), 1
is a reference to the first component of A.

So long as you are using arrays, you are using referential semantics. The
only way to avoid it is to directly embed an object directly in an enclosing
object (as in a record), and that doesn't work for many problems.

....
> I don't see anything that is not already there. What are reasons for not
> providing:
>
> M (n) [ e.g. M (n).Key, M (n).Value ]
> M (n1..n2) [ in mutable contexts too ]
> M'First
> M'Last
> M1 & M2 [ M1 or M2 ]
>
> They are all well-defined and useful operations.

Performance. If all of these things are user-definable, then one has to use
subprogram calls to implement all of them. That can be very expensive,
particularly in the case of mutable operations (and mutable slices are the
worst of all). Moreover, since one would want the ability to have generic
and runtime parameters that only meet this interface (and the ability to
pass slices to subprograms that take unconstrained array parameters), you
would have to be able to pass all of these subprograms along with
parameters, even when you don't need them. That would make array operations
far more expensive than they are today.

I think it is much better to get rid of most of these operations as built-in
things and just let the programmer build their own operations as needed.
That keeps the cost confined to those who use them. Distributed overhead is
the worst kind, and slices in particular have a boatload of that overhead.

Randy.

Re: Map iteration and modification

<un2jrc$3324e$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10350&group=comp.lang.ada#10350

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Tue, 2 Jan 2024 21:22:00 -0600
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <un2jrc$3324e$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info> <umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me> <umldsq$na79$1@dont-email.me> <umm4r5$ppag$1@dont-email.me> <ummn4v$s6gr$1@dont-email.me> <ummtfl$t4uo$1@dont-email.me> <umv3nn$2adp0$1@dont-email.me> <umv8rg$2b4on$1@dont-email.me>
Injection-Date: Wed, 3 Jan 2024 03:21:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="56dd089a60772e36f9749f23e307c802";
logging-data="3246222"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+DbqTZ/KCjcGH668FV25yfYfMBlZWgsWA="
Cancel-Lock: sha1:W6abW4IMgCIcwLJ7dN4ZN7ERAIc=
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-Priority: 3
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-RFC2646: Format=Flowed; Response
 by: Randy Brukardt - Wed, 3 Jan 2024 03:22 UTC

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:umv8rg$2b4on$1@dont-email.me...
....
> It is same benefit Ada arrays have over C's T* pointers and arithmetic of.
> Cursor is merely a fat pointer.

A cursor is an abstract reference. It *might* be implemented with a pointer
or with an array index. Indeed, the bounded containers pretty much have to
be implemented with an underlying array.

It would be nice if there was some terminology for abstract references that
hadn't been stolen by some programming language. Terms like "pointer" and
"access" and "reference" all imply an implementation strategy. That's not
relevant most of the time, and many programming language design mistakes
follow from that. (Anonymous access types come to mind).

Randy.

Re: Map iteration and modification

<kvk4p7Ffv1bU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10351&group=comp.lang.ada#10351

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: findlaybill@blueyonder.co.uk (moi)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Wed, 3 Jan 2024 04:05:59 +0000
Lines: 22
Message-ID: <kvk4p7Ffv1bU1@mid.individual.net>
References: <umjukd$9sp$1@rasp.pasdenom.info>
<umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me>
<umldsq$na79$1@dont-email.me> <umm4r5$ppag$1@dont-email.me>
<ummn4v$s6gr$1@dont-email.me> <ummtfl$t4uo$1@dont-email.me>
<umv3nn$2adp0$1@dont-email.me> <umv8rg$2b4on$1@dont-email.me>
<un2jrc$3324e$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net WhDBxmCZAjy7NGWG3TlQ6wgJYiEJw1fZurXEUavbcgUw9qe0AW
Cancel-Lock: sha1:rlqzgecYIcoqcD7wRY4E+c+nFWA= sha256:L04CQHsNcRsFHwXIp0bRh8BuW98SsBrTbXWLtBgkA0A=
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
In-Reply-To: <un2jrc$3324e$1@dont-email.me>
 by: moi - Wed, 3 Jan 2024 04:05 UTC

On 03/01/2024 03:22, Randy Brukardt wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:umv8rg$2b4on$1@dont-email.me...
> ...
>> It is same benefit Ada arrays have over C's T* pointers and arithmetic of.
>> Cursor is merely a fat pointer.
>
> A cursor is an abstract reference. It *might* be implemented with a pointer
> or with an array index. Indeed, the bounded containers pretty much have to
> be implemented with an underlying array.
>
> It would be nice if there was some terminology for abstract references that
> hadn't been stolen by some programming language. Terms like "pointer" and
> "access" and "reference" all imply an implementation strategy. That's not
> relevant most of the time, and many programming language design mistakes
> follow from that. (Anonymous access types come to mind).

What about "currency", as used in DB systems?

--
Bill F.

Re: Map iteration and modification

<un3bg9$35mhv$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10352&group=comp.lang.ada#10352

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Wed, 3 Jan 2024 11:04:58 +0100
Organization: A noiseless patient Spider
Lines: 165
Message-ID: <un3bg9$35mhv$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info>
<umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me>
<umldsq$na79$1@dont-email.me> <umm4r5$ppag$1@dont-email.me>
<umogc5$173bb$1@dont-email.me> <umotm2$18lqm$1@dont-email.me>
<un2jeb$330jr$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 3 Jan 2024 10:04:57 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8f506eb6ab43640b6ac40dc655b94447";
logging-data="3332671"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18roKq7T+tK6mXGg/m9K4AjOjt6q0sSX8s="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:5LxVPZH3x8a3TaOGWfoCRth4RJs=
In-Reply-To: <un2jeb$330jr$1@dont-email.me>
Content-Language: en-US
 by: Dmitry A. Kazakov - Wed, 3 Jan 2024 10:04 UTC

On 2024-01-03 04:15, Randy Brukardt wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:umotm2$18lqm$1@dont-email.me...
> ...
>>> Only as far as there is an order implied by the order that things are
>>> returned. That order doesn't have any meaning, and certainly there isn't
>>> any
>>> such thing as "forward" or "reverse" to it. (Which was the original
>>> claim,
>>> after all.) There is no "natural" order to the key/element pairs; they
>>> are
>>> effectively unordered.
>>
>> Iteration = order. It is the same thing. If you provide iteration of pairs
>> in the mapping by doing so you provide an order of.
>
> Certainly not. An iteration presents all of the elements in a container, but
> there is no requirement that there is an order.

The meaning of the word "iterate" is doing something (e.g. visiting an
element) again. That *is* an order.

> Indeed, logically, all of
> the elements are presented at the same time (and parallel iteration provides
> an approximation of that).

Parallel iteration changes nothing because involved tasks are enumerated
and thus ordered as well.

> If you try to enforce an order on things that don't require it, you end up
> preventing useful parallelism (practically, at least, no one has succeeded
> at providing useful parallelism to sequential code and people have been
> trying for about 50 years -- they were trying when I was a university
> student in the late 1970s).

Ordering things does not prevent parallelism. But storing cursors for
later is a mother of all Sequentialisms! (:-))

Whether a container elements can be effectively deleted in parallel is
an interesting but rather unpractical one. Nobody, literally nobody,
cares because any implementation would be many times slower than the
worst sequential one! (:-))

>>>> It always does sense *IF* enumeration (needed for iteration) is
>>>> provided.
>>>> Enumeration of pairs (<key>, <value>) is not same as ordering values by
>>>> the keys.
>>>
>>> True, but it doesn't imply any particular ordering. Certainly, no concept
>>> of
>>> "forward" or "reverse" applies to such an ordering (nor any stability
>>> requirement).
>>
>> It does. You have a strict total order of pairs which guarantees existence
>> of previous and next pairs according to.
>
> Again, this is unrelated. Iteration can usefully occur in unordered
> containers (that is, "foreach").

"An enumeration is a complete, ordered listing of all the items in a
collection."
-- Wikipedia

If "foreach" exposes an arbitrary ordering rather than some meaningful
(natural) one, that speaks for "insanity" but changes nothing.

> Ordering is a separate concept, not always
> needed (certainly not in basic structures like maps, sets, and bags).

Right. But no ordering means no iteration, no foreach etc. If I can
iterate, that I can create an ordered set of (counter, element) pairs. Done.

>> Yes position is a property of enumeration.
>
> Surely not. This is a basis for my disagrement with you here.

Then you are disagreeing with core mathematics... (:-))

> The only
> requirement for enumeration is that all elements are produced.

Produced in an order. Elements only produced" is merely an opaque set.
Enumeration of that set is ordering its elements.

> The order is
> an artifact of doing it an inherently parallel operation sequentally.

Yes, ordering is an ability to enumerate elements of a set. It is not an
artifact it is the sole semantics of.

[...]

>>> You have some problem with an iterator
>>> interface as opposed to an array interface??
>>
>> Yes, I am against pointers (referential semantics) in general.
>
> This is nonsense - virtually everything is referential semantics (other than
> components). Array indexes are just a poor mans pointer (indeed, I learned
> how to program in Fortran 66 initially, and way one built useful data
> structures was to use array indexes as stand-ins for pointers). In A(1), 1
> is a reference to the first component of A.
>
> So long as you are using arrays, you are using referential semantics. The
> only way to avoid it is to directly embed an object directly in an enclosing
> object (as in a record), and that doesn't work for many problems.

The key difference is that index does not refer any element. It is
container + index that do.

From the programming POV it is about avoiding hidden states when you
try to sweep the container part under the rug.

>> I don't see anything that is not already there. What are reasons for not
>> providing:
>>
>> M (n) [ e.g. M (n).Key, M (n).Value ]
>> M (n1..n2) [ in mutable contexts too ]
>> M'First
>> M'Last
>> M1 & M2 [ M1 or M2 ]
>>
>> They are all well-defined and useful operations.
>
> Performance.

Irrelevant so long it does not tamper implementations of other operations.

> If all of these things are user-definable, then one has to use
> subprogram calls to implement all of them. That can be very expensive,
> particularly in the case of mutable operations (and mutable slices are the
> worst of all).

But better, faster, safer when implemented ad-hoc by the programmer? See
how this thread started. An elementary task, solved in a most
inefficient, crude and unmaintainable way...

> Moreover, since one would want the ability to have generic
> and runtime parameters that only meet this interface (and the ability to
> pass slices to subprograms that take unconstrained array parameters), you
> would have to be able to pass all of these subprograms along with
> parameters, even when you don't need them. That would make array operations
> far more expensive than they are today.

Yes, and the language separates mutable and immutable stuff when using
containers already. You cannot get around this issue.

> I think it is much better to get rid of most of these operations as built-in
> things and just let the programmer build their own operations as needed.

Well, if you'd proposed throwing containers out the standard library I
would believe that you believe in that... (:-))

> That keeps the cost confined to those who use them. Distributed overhead is
> the worst kind, and slices in particular have a boatload of that overhead.

Usability always trumps performance. And again, looking at the standard
containers and all these *tagged* *intermediate* objects one needs in
order to do elementary things, I kind of in doubts... (:-))

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Map iteration and modification

<un5asc$3hsqb$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10353&group=comp.lang.ada#10353

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Wed, 3 Jan 2024 22:07:30 -0600
Organization: A noiseless patient Spider
Lines: 175
Message-ID: <un5asc$3hsqb$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info> <umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me> <umldsq$na79$1@dont-email.me> <umm4r5$ppag$1@dont-email.me> <umogc5$173bb$1@dont-email.me> <umotm2$18lqm$1@dont-email.me> <un2jeb$330jr$1@dont-email.me> <un3bg9$35mhv$1@dont-email.me>
Injection-Date: Thu, 4 Jan 2024 04:06:36 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="369de39bb3b248004d8e62c851596a7d";
logging-data="3732299"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Ynkjte2ZaX6Xtx5J52g0ngM+IDB48/0I="
Cancel-Lock: sha1:FbIk+yOOLs6oHoKLMgTA+RHkASQ=
X-RFC2646: Format=Flowed; Response
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-Priority: 3
 by: Randy Brukardt - Thu, 4 Jan 2024 04:07 UTC

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:un3bg9$35mhv$1@dont-email.me...
> On 2024-01-03 04:15, Randy Brukardt wrote:
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>> news:umotm2$18lqm$1@dont-email.me...
....
> The meaning of the word "iterate" is doing something (e.g. visiting an
> element) again. That *is* an order.

The order is an artifact. One logically visits all of the elements at the
same time (certainly in an unordered container like a general map).

>> Indeed, logically, all of
>> the elements are presented at the same time (and parallel iteration
>> provides
>> an approximation of that).
>
> Parallel iteration changes nothing because involved tasks are enumerated
> and thus ordered as well.

Nonsense. There is no interface in Ada to access logical threads (the ones
created by the parallel keyword).

>> If you try to enforce an order on things that don't require it, you end
>> up
>> preventing useful parallelism (practically, at least, no one has
>> succeeded
>> at providing useful parallelism to sequential code and people have been
>> trying for about 50 years -- they were trying when I was a university
>> student in the late 1970s).
>
> Ordering things does not prevent parallelism.

Yes it does, because it adds unnecessary constraints. It's those constraints
that make parallelizing normal sequenatial code hard. A parallelizer has to
guess which ones are fundamental to the code meaning and which ones are not.

....
>> Ordering is a separate concept, not always
>> needed (certainly not in basic structures like maps, sets, and bags).
>
> Right. But no ordering means no iteration, no foreach etc. If I can
> iterate, that I can create an ordered set of (counter, element) pairs.
> Done.
>
>>> Yes position is a property of enumeration.
>>
>> Surely not. This is a basis for my disagrement with you here.
>
> Then you are disagreeing with core mathematics... (:-))

You are adding an unnecessary property to the concept of iteration.
Iteration does not necessarily imply enumeration (it can, of course).
Iteration /= enumeration.

....
>> The order is
>> an artifact of doing it an inherently parallel operation sequentally.
>
> Yes, ordering is an ability to enumerate elements of a set. It is not an
> artifact it is the sole semantics of.

Iteration is not necessarily enumeration. It is applying an operation to all
elements, and doing that does not require an order. Some specific operations
might require an order, and clearly for those one needs to use a data
structure that inherently has an order.
....
>> So long as you are using arrays, you are using referential semantics. The
>> only way to avoid it is to directly embed an object directly in an
>> enclosing
>> object (as in a record), and that doesn't work for many problems.
>
> The key difference is that index does not refer any element. It is
> container + index that do.

That's not a "key difference". That exactly how one should use cursors,
especially in Ada 2022. The Ada containers do have cursor-only operations,
but those should be avoided since it is impossible to provide useful
contracts for those operations (the container is unknown, so the world can
be modified, which is bad for parallelism and understanding). Best to
consider those operations obsolete. (Note that I was *always* against the
cursor-only operations in the containers.)

So, using a cursor implies calling an operation that includes the container
of its parameter.

> From the programming POV it is about avoiding hidden states when you try
> to sweep the container part under the rug.

That's easily avoided -- don't use the obsolete operations. (And a style
tool like Jean-Pierre's can enforce that for you.)

>>> I don't see anything that is not already there. What are reasons for not
>>> providing:
>>>
>>> M (n) [ e.g. M (n).Key, M (n).Value ]
>>> M (n1..n2) [ in mutable contexts too ]
>>> M'First
>>> M'Last
>>> M1 & M2 [ M1 or M2 ]
>>>
>>> They are all well-defined and useful operations.
>>
>> Performance.
>
> Irrelevant so long it does not tamper implementations of other operations.

Exactly. These operations, especially slicing, have a huge impact on the
cost of parameter passing for arrays (whether or not they are used). And
that's a pretty fundamental operation.

>> If all of these things are user-definable, then one has to use
>> subprogram calls to implement all of them. That can be very expensive,
>> particularly in the case of mutable operations (and mutable slices are
>> the
>> worst of all).
>
> But better, faster, safer when implemented ad-hoc by the programmer?

As with all programming problems, you can only have two of the three. ;-)

If the underlying programming language is already better and safer, that
extends to user-written operations. (If it doesn't, it is a failure.)

....
....
>> I think it is much better to get rid of most of these operations as
>> built-in
>> things and just let the programmer build their own operations as needed.
>
> Well, if you'd proposed throwing containers out the standard library I
> would believe that you believe in that... (:-))

The standard library is not part of the programming language. It's a
necessary adjunct, but it could be completely replaced without changing the
language at all. It's necessary mainly so that basic operations are provided
in the same way by all implementations, but there is little requirement to
use it.

Specifically, the containers are separate from Ada. Plenty of programmers
use their own container libraries, with different performance and safety
profiles. That's expected and intended. There is no one-size-fits-all (or
even one-size-fits-many) container library.

>> That keeps the cost confined to those who use them. Distributed overhead
>> is
>> the worst kind, and slices in particular have a boatload of that
>> overhead.
>
> Usability always trumps performance.

That's the philosophy of languages like Python, not Ada. If you truly
believe this, then you shouldn't be using Ada at all, since it makes lots of
compromises to usability in order to get performance.

> And again, looking at the standard containers and all these *tagged*
> *intermediate* objects one needs in order to do elementary things, I kind
> of in doubts... (:-))

The standard containers were designed to make *safe* containers with decent
performance. As I noted, they're not a built-in part of the programming
language, and as such have no impact on the performance of the language
proper. One could easily replace them with an unsafe design to get maximum
performance -- but that would have to return pointers to elements, and
you've said you don't like referential semantics. So you would never use
those.

You also can avoid all of the "tagged objects" (really controlled objects)
by using function Element to get a copy of the element rather than some sort
of reference to it. That's preferred if it doesn't cost too much for your
application.

Randy.

Re: Map iteration and modification

<un64o3$3krch$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10354&group=comp.lang.ada#10354

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Thu, 4 Jan 2024 12:28:04 +0100
Organization: A noiseless patient Spider
Lines: 102
Message-ID: <un64o3$3krch$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info>
<umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me>
<umldsq$na79$1@dont-email.me> <umm4r5$ppag$1@dont-email.me>
<umogc5$173bb$1@dont-email.me> <umotm2$18lqm$1@dont-email.me>
<un2jeb$330jr$1@dont-email.me> <un3bg9$35mhv$1@dont-email.me>
<un5asc$3hsqb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 4 Jan 2024 11:28:03 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f5ce3a56fb13d510cf983b765108175f";
logging-data="3829137"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ErfqwVAM5tRDFGcLe4LWPY0w+rF0AI+k="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:D7iwNO3k6Tnyz5SdWJNNJ66O6ls=
In-Reply-To: <un5asc$3hsqb$1@dont-email.me>
Content-Language: en-US
 by: Dmitry A. Kazakov - Thu, 4 Jan 2024 11:28 UTC

On 2024-01-04 05:07, Randy Brukardt wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:un3bg9$35mhv$1@dont-email.me...

[...]

>> Yes, ordering is an ability to enumerate elements of a set. It is not an
>> artifact it is the sole semantics of.
>
> Iteration is not necessarily enumeration. It is applying an operation to all
> elements, and doing that does not require an order.

That is not iteration, it is unordered listing, a totally useless thing
because the result is the same unordered set.

You could not implement it without prior ordering of the elements you
fed to the threads. If the threads picked up elements concurrently there
would be no way to do that without ordering elements into a taken / not
yet taken order. Hell, you cannot even get an element from a truly
unordered set, no way! If the programmer tried to make any use of the
listing he would again have to impose ordering when collecting results
per some shared object.

The unordered listing is a null operation without ordering.

>> The key difference is that index does not refer any element. It is
>> container + index that do.
>
> That's not a "key difference". That exactly how one should use cursors,
> especially in Ada 2022. The Ada containers do have cursor-only operations,
> but those should be avoided since it is impossible to provide useful
> contracts for those operations (the container is unknown, so the world can
> be modified, which is bad for parallelism and understanding). Best to
> consider those operations obsolete. (Note that I was *always* against the
> cursor-only operations in the containers.)
>
> So, using a cursor implies calling an operation that includes the container
> of its parameter.

OK. It is some immensely over-designed index operation, then! (:-)) So,
my initial question is back, why all that overhead? When you cannot do
elementary things like preserving your indices from a well-defined set
of upon deleting elements with indices outside that set?

>>>> I don't see anything that is not already there. What are reasons for not
>>>> providing:
>>>>
>>>> M (n) [ e.g. M (n).Key, M (n).Value ]
>>>> M (n1..n2) [ in mutable contexts too ]
>>>> M'First
>>>> M'Last
>>>> M1 & M2 [ M1 or M2 ]
>>>>
>>>> They are all well-defined and useful operations.
>>>
>>> Performance.
>>
>> Irrelevant so long it does not tamper implementations of other operations.
>
> Exactly. These operations, especially slicing, have a huge impact on the
> cost of parameter passing for arrays (whether or not they are used). And
> that's a pretty fundamental operation.

It is not slicing it is dynamically constrained arrays which are
required anyway. A general problem of language design is how to treat
statically known constraints effectively.

Ada arrays are pretty good to me. Note, I am saying that after years of
using Ada arrays for interfacing C! Yes, I would like having more
support for flattening arrays, but the mere fact that Ada can interface
C using *in-place* semantics invalidates your point.

> Specifically, the containers are separate from Ada.

Not really. Like STL with C++ it massively influenced the language
design motivating adding certain language features and shifting general
language paradigm in certain direction.

>> Usability always trumps performance.
>
> That's the philosophy of languages like Python, not Ada.

Ah, this is why Python is totally unusable? (:-))

Ada is usable and performant because of right abstractions it deploys.
If you notice performance problems then, maybe, just my guess, you are
using a wrong abstraction?

>> And again, looking at the standard containers and all these *tagged*
>> *intermediate* objects one needs in order to do elementary things, I kind
>> of in doubts... (:-))
>
> The standard containers were designed to make *safe* containers with decent
> performance.

Well, we always wish the best... (:-))

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Map iteration and modification

<un7nqe$3rs9n$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10355&group=comp.lang.ada#10355

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: Map iteration and modification
Date: Thu, 4 Jan 2024 20:00:37 -0600
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <un7nqe$3rs9n$1@dont-email.me>
References: <umjukd$9sp$1@rasp.pasdenom.info> <umjuvc$9sp$2@rasp.pasdenom.info> <umk6ds$e9hc$1@dont-email.me> <umldsq$na79$1@dont-email.me> <umm4r5$ppag$1@dont-email.me> <umogc5$173bb$1@dont-email.me> <umotm2$18lqm$1@dont-email.me> <un2jeb$330jr$1@dont-email.me> <un3bg9$35mhv$1@dont-email.me> <un5asc$3hsqb$1@dont-email.me> <un64o3$3krch$1@dont-email.me>
Injection-Date: Fri, 5 Jan 2024 01:59:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ef5742db43e50af7920779a9b0b05274";
logging-data="4059447"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184/7T8Dbw3M0BLEKWRUSuoW7cZRPUXkTk="
Cancel-Lock: sha1:ifh6LGxVeeqMQOMg5uaTJoy9d28=
X-Priority: 3
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-MSMail-Priority: Normal
 by: Randy Brukardt - Fri, 5 Jan 2024 02:00 UTC

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:un64o3$3krch$1@dont-email.me...
....
>> Exactly. These operations, especially slicing, have a huge impact on the
>> cost of parameter passing for arrays (whether or not they are used). And
>> that's a pretty fundamental operation.
>
> It is not slicing it is dynamically constrained arrays which are required
> anyway. A general problem of language design is how to treat statically
> known constraints effectively.

No, it's the combination of slicing and passing arrays with unknown (at
compile-time) constraints that causes problems. And it only causes problems
if you want to separate the array interface and the array implementation
(which we both want to do). In such a case, you are passing arrays with
unknown constraints and implementation. Assignable slices don't work with
that, as they require a contiguous implementation of elements. You could
work around that in various ways (passing slices by copy-result, passing an
assignment routine along with the parameter), but all of them have
substantial performance impacts that would make traditional array
implementations much slower.

> Ada arrays are pretty good to me. Note, I am saying that after years of
> using Ada arrays for interfacing C! Yes, I would like having more support
> for flattening arrays, but the mere fact that Ada can interface C using
> *in-place* semantics invalidates your point.

Inferfacing is using the array implementation, not the array interface. Of
course it works great, as you note Ada commingles those in a way that makes
them inseparable. To separate them, you are going to have to lose something.
I chose slices and other array-specific operations as a built-in as that
something. YMMV.

....
>>> Usability always trumps performance.
>>
>> That's the philosophy of languages like Python, not Ada.
>
> Ah, this is why Python is totally unusable? (:-))

I would tend to argue that it is indeed the case that you get dubious
results when you put usability first. Ada puts
readability/understandability, maintainability, and consistency first (along
with performance). Those attributes tend to provide usability, but not at
the cost of making things less consistent or understandable.

I wrote an article on this topic a year and a half ago that I wanted to
publish on Ada-Auth.org. But I got enough pushback about not being "neutral"
that I never did so. (I don't think discussing why we don't do things some
other languages do is negative, but whatever.) I've put this on RR's blog at
http://www.rrsoftware.com/html/blog/consequences.html so it isn't lost.

Randy.

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor