Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding unions of objects in lists (compound objects / nested lists)
    primarykey
    data
    text
    <p>(<strong>I have rewritten the question to try to better provide an example of what I am trying to do. I apologize if this is a confusing question still...</strong>)</p> <p>In what way would it be possible to find the union of n-many sets of objects that are contained as properties of other objects?</p> <p>Using the following as an example:</p> <pre><code>class Author { public string FirstName; public string LastName; } class Magazine { public string Title; public string ISBN; public List&lt;Article&gt; TOC; } class Article { public string Title; public string Header; public string Body; public int PageNumber; public Magazine Source; public Author Author; } </code></pre> <ul> <li>I am given a <code>List&lt;Magazine&gt;</code> which contains a <code>List&lt;Article&gt;</code>.</li> <li>The Article object has a Magazine and Author objects as properties (the article may exist 1:N to the magazine - as a copy or reprint).</li> <li>In fact, I am treating each article as an independent object. I do not care about the <code>List&lt;Magazine&gt;</code> which was given to me. I have been asked to provide a <code>List&lt;Author&gt;</code>.</li> <li>Before being given this List, I have <strong>NO</strong> knowledge of the possible Articles or Authors.</li> </ul> <p>This data which I am provided looks like this (in treeview layout).</p> <pre><code>Magazine01 Article01 (Title, Header, ... Magazine01, Author01) Article02 (Title, Header, ... Magazine01, Author02) Article03 (Title, Header, ... Magazine01, Author03) Magazine02 Article04 (Title, Header, ... Magazine02, Author04) Article05 (Title, Header, ... Magazine02, Author05) Article06 (Title, Header, ... Magazine02, Author04) Magazine03 Article07 (Title, Header, ... Magazine03, Author03) Article08 (Title, Header, ... Magazine03, Author02) Article09 (Title, Header, ... Magazine03, Author01) </code></pre> <p>This data which I have been asked to provide looks like this (in treeview layout).</p> <pre><code>Author01 Article01 (Title, Header, ... Magazine01, Author01) Article09 (Title, Header, ... Magazine03, Author01) Author02 Article02 (Title, Header, ... Magazine01, Author02) Article08 (Title, Header, ... Magazine03, Author02) Author03 Article03 (Title, Header, ... Magazine01, Author03) Article07 (Title, Header, ... Magazine03, Author03) Author04 Article04 (Title, Header, ... Magazine02, Author04) Article06 (Title, Header, ... Magazine02, Author04) Author05 Article05 (Title, Header, ... Magazine02, Author05) </code></pre> <ul> <li>The <code>List&lt;Magazine&gt;</code> I am given will be in no particular order.</li> <li>I am not trying to sort the output yet, but that would be nice.</li> <li>There may be n-many Magazines where each issue has n-many Articles.</li> <li>As a result, an Author may have n-many Articles.</li> <li>As I receive the Magazine objects, I am aggregating the Articles into a <code>List&lt;Article&gt;</code> (but I am not dead set on continuing to do this, it <em>seemed</em> like a good idea...)</li> </ul> <hr> <p>In what way can I reduce the looping through the list of articles other than my (shameful) "reduction by attrition" method below:</p> <pre><code>List&lt;Magazine&gt; magazineList; // Magazines contain a list of Articles which contain an Author. List&lt;Article&gt; articleList; // As each Magazine is created, a summary list of the Articles is recorded here (I realize that this is probably unnecessary, but that is an aside to my problem) Bag&lt;Author&gt; authorBag; for (i = 0; i &lt; (Magazines.Count - 1); i++) { BuildAuthorBag(); } ParseArticleList(); //... BuildAuthorBag() { // Finds occurrences of Author in the Article list of each Magazine. // Limits the inclusion of Author based on preferences ( i &gt; 1, 2, etc. ) } ParseArticleList() { // I clone the articleList (i.e. tmpArticleList) // I create two lists of Article type. One will be the new leaf nodes. The second is a swap list. // Using the authorBag... // In a loop... // I create the new parent node from the current Author in the bag. // Then, find occurrences of the Author in the tmpArticleList adding that Article as a child node to the parent node. // or... // I place them into the second list to be swapped for the tmpArticleList before the next loop. } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload