From mboxrd@z Thu Jan 1 00:00:00 1970 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "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 Message-ID: References: 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 Xref: news.eternal-september.org comp.lang.ada:65945 List-Id: "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.