From mboxrd@z Thu Jan 1 00:00:00 1970 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "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 Message-ID: References: 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: Content-Language: en-US Xref: news.eternal-september.org comp.lang.ada:65942 List-Id: On 29.12.23 10:51, Dmitry A. Kazakov wrote: > On 2023-12-29 04:20, Randy Brukardt wrote: >> "Dmitry A. Kazakov" 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);