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 8653535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:34:05+00:00 2026-06-12T14:34:05+00:00

I have several data sources, each of which provides ordered timestamped data. I’d like

  • 0

I have several “data sources”, each of which provides ordered timestamped data. I’d like to flatten it into a single ordered stream (like merge sort). This answer describes how to do it for two enumerables, but I am not sure how to generalize it.

Data sources are huge, so I cannot do it in memory, it has to be streamed.

To explain it with an example, I have something like this:

interface IDataSource
{
    IEnumerable<DateTime> GetOrderedRecords();
}

I would like to be able to have an extension method like this:

// get all sources
IEnumerable<IDataSource> dataSources = GetAllSources();

// merge sort
IEnumerable<DateTime> flattened = dataSources
    .MergeSort(s => s.GetOrderedRecords());

[Edit]

The reason I can’t load everything eagerly and then sort it is because I am loading data from multiple databases and exporting it into a different one. Each IDataSource is basically Linq-to-NHibernate under the hood, and I have millions of data rows to return.

So what I need is something like:

  1. From all available sources, load the next timestamp.
  2. Store it to disk and “forget it”.

Data sources are already sorted, which makes the “merge sort” approach feasible.

  • 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-12T14:34:06+00:00Added an answer on June 12, 2026 at 2:34 pm

    One simple thing you could do is to concat the calls to the Merge implementation from the question you linked:

    public static IEnumerable<DateTime> Merge(this IEnumerable<IDataSource> dataSources)
    {
        var result = Enumerable.Empty<DateTime>();
    
        foreach(var dataSource in dataSources)
        {
            result = result.Merge(dataSource.GetOrderedRecords(), (x, y) => x < y);
        }
    
        return result;
    }
    

    You would call it like this:

    var result = dataSources.Merge();
    

    This has the drawback that each call to MoveNext on the enumerator of the returned enumerable yields quite a lot of MoveNext calls on the nested enumerables.

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

Sidebar

Related Questions

I have written an importer which copies data from a flat table into several
I have several data that looks like this: Vector1_elements = T,C,A Vector2_elements = C,G,A
I have several complex data structures like Map< A, Set< B > > Set<
I have several classes with static const data members. I would like to know
I have several objects set up in Core Data, one of which is Deck
I have several similar user controls which display listviews of respectively different data entities.
I have two sources: an xml-file containing definitions of several hundred data structures, basically
I have set up a test that: retrieves data concerning several court cases: each
I have a situation which involves several threads simultaneously populating a database with data
I have a spring web application which has several modules. Each module has its

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.