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

  • Home
  • SEARCH
  • 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 444509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:16:39+00:00 2026-05-12T21:16:39+00:00

Say I have a class public class TimestampedTrackId { private readonly int trackId; private

  • 0

Say I have a class

public class TimestampedTrackId
{
    private readonly int trackId;
    private readonly DateTime insertTime;
    public TimestampedTrackId(int trackId, DateTime insertTime)
    {
        this.trackId = trackId;
        this.insertTime = insertTime;
    }

    public int TrackId
    {
        get
        {
            return trackId;
        }
    }

    public DateTime InsertTime
    {
        get
        {
            return insertTime;
        }
    }
}

I have a large list of type List<TimestampedTrackId> and need to extract TimestampedTrackId instances from this list where the property InsertTime lies between a minimum and a maximum DateTime.

List<TimestampedTrackId> tracks; //Count=largeNumber
... 
tracks.Where(t=>t.InsertTime>min&&t.InsertTime<max)

A List<T> is obviously not the correct container for this task as it requires a search on every item to check if InsertTime lies between the min and max values.

So, I am assuming that part of speeding up this code would involve repackaging the list in a more suitable collection, but which collection?

Given the correct collection (which might be keyed), what query might I use to leverage maximum lookup speed?

Thanks in advance

  • 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-05-12T21:16:40+00:00Added an answer on May 12, 2026 at 9:16 pm

    Are you able to sort your list by InsertTime? If so, List<T>.BinarySearch is your friend – provide an IComparer<TimestampedTrackId> which compares by InsertTime, and BinarySearch for min and max. (You’ll need to create “dummy” TimestampedTrackId objects with an InsertTime values of min and max in order to search for them.)

    If BinarySearch returns a negative value, you should take the bitwise complement (using the ~ operator) to find out the index where the value would be inserted. Also remember that if multiple items can have the same InsertTime, you’ll need to work backwards from the min index and forwards from the max index to make sure you get the full range. Anyway, it’ll still be a lot more efficient than a linear search. It’s a bit more fiddly, admittedly 🙂

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

Sidebar

Related Questions

So say I have this class: public class PositionList { private Position[] data =
Say I have the following class: public MainFormViewModel { public String StatusText {get; set;}
Say I have this C# class: public class HttpContextEx { public HttpContext context =
Say we have class public class Entry<K, V> { public Entry(K k,V v) {
Let's say I have a class public class foo { public string FooId {
Say I have my own class public class MyObj { /* ... */ }
Let's say I have some basic interface which is generics-driven: public interface Inteface<T> {
I'm using the Play! framework and I have a model (an Entity) that has
Using a library like ASM or cglib , is there a way to add
I've been sifting through AutoMapper documentation to try and find a recommended solution to

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.