From mboxrd@z Thu Jan 1 00:00:00 1970 Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.gegeweb.eu!gegeweb.org!pasdenom.info!.POSTED.2a01:e0a:472:70f0:a9b2:5554:1dc8:f27e!not-for-mail From: DrPi <314@drpi.fr> Newsgroups: comp.lang.ada Subject: Re: Map iteration and modification Date: Sun, 31 Dec 2023 14:56:05 +0100 Organization: Message-ID: References: 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: Content-Language: fr Xref: news.eternal-september.org comp.lang.ada:65948 List-Id: 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