CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: graphs (union, intersection,

    Though you have the word "graphs" is your thread title, your question actually seems to rather be about sets. And, funnily, just right now I'm working on a real-life program where they do a good job for me. However, perhaps it's rather abstract to explain the practical use of sets of integers, and in my program it actually are sets of strings.

    Say you want to track changes of the inventory of files in a certain domain (say a certain disk directory, though it's somewhat more complex in the real app). Now I have a list of names of files that have been there at a certain earlier point in time and a list of files that are there right now. I put both the lists into a set of strings (std::set<std::string>) each.

    Now the intersection of the two sets contains the files that have been there before and are still there (though their content may have chaged; we're just checking the names), and the union of the sets contains the files that have been there before and/or are there now (rather uninteresing in practice, IMO). What really interests me here, though, are the two asymmetric set differences (AKA relative complement, in C++ determined using std::set_difference()): One contains the files that have been there but have been deleted now, and the other one contains the files that are new, and these are the two sets of files I need to process further in my program. (For completeness note that, in this model, files that have been renamed in the meantime will show up in both the "deleted" an "new" sets under different names, and from the data we're considering here there's no way to know that it's actually the same file under different names. That's not a problem in my real-life app, though.)
    Last edited by Eri523; March 18th, 2012 at 10:58 AM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured