Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8708449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:08:24+00:00 2026-06-13T04:08:24+00:00

i am looking for a way to reconcile elements from 3 different sources. i’ve

  • 0

i am looking for a way to reconcile elements from 3 different sources. i’ve simplified the elements to having just a key (string) and version (long).

the lists are attained concurrently (2 from separate database queries, and 1 from a memory cache on another system).

for my end result, i only care about elements that are not identical versions across all 3 sources. So the result i care about would be a list of keys, with corresponding versions in each system.

Element1 | system1:v100    | system2:v100 | system3:v101 |
Element2 | system1:missing | system2:v200 | system3:v200 |

and the elements with identical versions can be discarded.

The 2 ways of achieving this i thought of are

  1. wait for all datasources to finish retrieving, and than loop through each list to aggregate a master list with a union of keys + all 3 versions (discarding all identical items).

  2. as soon as the first list is done being retrieved, put it into a concurrent collection such as dictionary (offered in .net 4.0), and start aggregating remaining lists (into the concurrent collection) as soon as they are available.

my thinking is that second approach will be a little quicker, but probably not by much. i can’t really do much until all 3 sources are present, so not much is gained from 2nd approach and contention is introduced.

maybe there is a completely other way to go about this? Also, since versions are stored using longs, and there will be 100’s of thousands (possibly millions) of elements, memory allocation could be of concern (tho probably not a big concern since these objects are short lived)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:08:25+00:00Added an answer on June 13, 2026 at 4:08 am

    HashSet is an option as it has Union and Intersect methods

    HashSet.UnionWith Method

    To use this you must override Equals and GetHashCode.
    A good (unique) hash is key to performance.

    If the version is all v then numeric the could use the numeric to build the hash with missing as 0.
    Have Int32 to play with so if version is Int10 or less can create a perfect hash.

    Another option is ConcurrentDictionary (there is no concurrent HashSet) and have all three feed into it.
    Still need to override Equals and GetHashCode.
    My gut feel is three HashSets then Union would be faster.

    If all versions are numeric and you can use 0 for missing then could just pack into UInt32 or UInt64 and put that directly in a HashSet. After Union then unpack. Use bit pushing << rather than math to pack an unpack.

    This is just two UInt16 but it runs in 2 seconds.
    This is going to be faster than Hashing classes.

    If all three versions are long then HashSet<integral type> will not be an option.
    long1 ^ long2 ^ long3; might be a good hash but the is not my expertise.
    I know GetHashCode on a Tuple is bad.

    class Program
    {
        static void Main(string[] args)
        {
            HashSetComposite hsc1 = new HashSetComposite();
            HashSetComposite hsc2 = new HashSetComposite();
            for (UInt16 i = 0; i < 100; i++)
            {
                for (UInt16 j = 0; j < 40000; j++)
                {
                    hsc1.Add(i, j);
                }
                for (UInt16 j = 20000; j < 60000; j++)
                {
                    hsc2.Add(i, j);
                }
            }
            Console.WriteLine(hsc1.Intersect(hsc2).Count().ToString());
            Console.WriteLine(hsc1.Union(hsc2).Count().ToString());
        }
    }
    
    public class HashSetComposite : HashSet<UInt32>
    {
        public void Add(UInt16 u1, UInt16 u2)
        {      
            UInt32 unsignedKey = (((UInt32)u1) << 16) | u2;
            Add(unsignedKey);           
        }
        //left over notes from long
        //ulong unsignedKey = (long) key;
        //uint lowBits = (uint) (unsignedKey & 0xffffffffUL);
        //uint highBits = (uint) (unsignedKey >> 32);
        //int i1 = (int) highBits;
        //int i2 = (int) lowBits;
    }
    

    Tested using a ConcurrentDictionary and the above was over twice as fast.
    Taking locks on the inserts is expensive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for way to change all array's keys to one key for all
I'm looking for way to present equally sized elements in a fixed number of
I was looking the way to create a Task from an email at my
I am looking for a way to debug compiled assemblies from Visual Studio. Is
just looking a way to avoid repeated post on my site, here is a
Is there any fast (and nice looking) way to remove an element from an
im looking for way how to remove whole bodies from functions in some C
I'm looking for way to PHP to detect if a script was run from
I'm looking for way to create list view as like in IOS with pinned
I'm looking a way to enable IP logging with log4net in ASP.NET. I found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.