comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Map iteration and modification
Date: Mon, 1 Jan 2024 21:55:12 +0100	[thread overview]
Message-ID: <umv8rg$2b4on$1@dont-email.me> (raw)
In-Reply-To: <umv3nn$2adp0$1@dont-email.me>

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

  reply	other threads:[~2024-01-01 20:55 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-28 13:53 Map iteration and modification DrPi
2023-12-28 13:59 ` DrPi
2023-12-28 16:06   ` Dmitry A. Kazakov
2023-12-28 17:57     ` DrPi
2023-12-29  3:20     ` Randy Brukardt
2023-12-29  9:51       ` Dmitry A. Kazakov
2023-12-29 15:03         ` G.B.
2023-12-29 16:52           ` Dmitry A. Kazakov
2024-01-01 19:27             ` G.B.
2024-01-01 20:55               ` Dmitry A. Kazakov [this message]
2024-01-02 16:40                 ` G.B.
2024-01-02 20:57                   ` Dmitry A. Kazakov
2024-01-03  3:22                 ` Randy Brukardt
2024-01-03  4:05                   ` moi
2023-12-30  7:21         ` Randy Brukardt
2023-12-30 11:07           ` Dmitry A. Kazakov
2024-01-03  3:15             ` Randy Brukardt
2024-01-03 10:04               ` Dmitry A. Kazakov
2024-01-04  4:07                 ` Randy Brukardt
2024-01-04 11:28                   ` Dmitry A. Kazakov
2024-01-05  2:00                     ` Randy Brukardt
2024-01-05  9:26                       ` Simon Wright
2024-01-05 11:51                       ` Dmitry A. Kazakov
2024-01-06  7:25                         ` Randy Brukardt
2024-01-07 15:06                           ` Jeffrey R.Carter
2024-01-09  4:46                             ` Randy Brukardt
2024-01-09  5:56                               ` when-clauses (was Re: Map iteration and modification) Lawrence D'Oliveiro
2024-01-09  9:43                               ` Map iteration and modification Jeffrey R.Carter
2024-04-17 10:12                         ` Cóilín Nioclás Pól Glostéir
2024-01-06  2:54                       ` “Usability” (was Re: Map iteration and modification) Lawrence D'Oliveiro
2024-01-06  7:03                         ` "Usability" " Randy Brukardt
2024-01-06  8:14                           ` Niklas Holsti
2024-01-06 23:41                           ` Lawrence D'Oliveiro
2024-01-07  1:21                           ` J-P. Rosen
2024-01-09 15:19                             ` Bill Findlay
2024-01-09 20:30                             ` Lawrence D'Oliveiro
2023-12-29  3:08   ` Map iteration and modification Randy Brukardt
2023-12-29 13:53     ` DrPi
2023-12-30  6:29       ` Randy Brukardt
2023-12-31 13:56         ` DrPi
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox