From: Christian Franke <Christian.Franke@t-online.de>
To: Jon Turney <jon.turney@dronecode.org.uk>,
"cygwin-apps@cygwin.com" <cygwin-apps@cygwin.com>
Subject: Re: [PATCH setup 2/2] Detect filename collisions between packages
Date: Thu, 27 Apr 2023 19:20:25 +0200 [thread overview]
Message-ID: <087e05db-80e5-f800-1533-51ae93c67079@t-online.de> (raw)
In-Reply-To: <358f3794-ea6c-d771-731b-34ab9bffde9b@dronecode.org.uk>
Jon Turney wrote:
> ...
>>> Using std::set_intersection() on values from std::map() here is
>>> probably
>>> a mistake. It's simple to write, but the performance is not good.
>>
>> A faster alternative which avoids set_intersection calls in a loop is
>> possibly to use one large data structure which maps filenames to sets
>> of packages. Using multimap<string, string> instead of the
>> straightforward map<string, set<string>> needs possibly less memory
>> (not tested). But for multimap it is required that file/package name
>> pairs are not inserted twice.
>>
>> I attached a small standalone POC source file using multimap. It
>> would also detect collisions in the already installed packages.
>
> Thanks for the ideas. It seems I really didn't think that carefully
> about this...
>
> It seems like maybe building a map from filename to the set of package
> names which contain it, and then finding all the filenames where that
> set has more than one member would be a possible better implementation.
Of course this is the more obvious method and easier to implement. It is
somewhat slower and needs more memory.
Meantime I did a quick artificial test with 10000 "packages" with 100
"files" each and 2 collisions. This resulted in a (multi)map size if
1000000(+2), total size of strings was ~80MB. Results:
Data structure: execution time, memory (working set)
multimap<string, string>: 1.8 seconds, 238MB
map<string, set<string>>: 2.0 seconds, 318MB
The execution time is needed for the map insertions. The final scan for
collisions is very fast in both cases.
next prev parent reply other threads:[~2023-04-27 17:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-23 14:43 [PATCH setup 0/2] " Jon Turney
2023-04-23 14:43 ` [PATCH setup 1/2] Add underlying() method to io_stream class Jon Turney
2023-04-23 14:43 ` [PATCH setup 2/2] Detect filename collisions between packages Jon Turney
2023-04-24 16:26 ` Christian Franke
2023-04-27 16:11 ` Jon Turney
2023-04-27 17:20 ` Christian Franke [this message]
2023-04-24 16:46 ` [PATCH setup 0/2] " Corinna Vinschen
2023-04-24 18:16 ` Achim Gratz
2023-04-27 16:11 ` Jon Turney
2023-04-28 5:51 ` Brian Inglis
2023-04-30 18:25 ` Jon Turney
2023-05-04 4:14 ` Brian Inglis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=087e05db-80e5-f800-1533-51ae93c67079@t-online.de \
--to=christian.franke@t-online.de \
--cc=cygwin-apps@cygwin.com \
--cc=jon.turney@dronecode.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).