Search Results

Search found 2 results on 1 pages for 'pygmy'.

Page 1/1 | 1 

  • c# binarysearch a list<T> by a member of T

    - by Pygmy
    I have a baseclass Event with a DateTime member TimeStamp. Lots of other event-classes will derive from this. I want to be able to search a list of events (that can contain events with duplicate timestamps) fast, so I'd like to use a binary search. So I started out writing something like this : public class EventList<T> : List<T> where T : Event { private IComparer<T> comparer = (x, y) => Comparer<DateTime>.Default.Compare(x.TimeStamp, y.TimeStamp); public IEnumerable<T> EventsBetween(DateTime inFromTime, DateTime inToTime) { // Find the index for the beginning. int index = this.BinarySearch(inFromTime, comparer); // BLAH REST OF IMPLEMENTATION } } The problem is that the BinarySearch only accepts T (so - an Event type) as parameter, while I want to search based on a member of T - the TimeStamp. What would be a good way to approach this ?

    Read the article

  • 2D Game: Fast(est) way to find x closest entities for another entity - huge amount of entities, high

    - by Pygmy
    I'm working on a 2D game that has a huge amount of dynamic entities. For fun's sake, let's call them soldiers, and let's say there are 50000 of them (which I just randomly thought up, it might be much more or much less :)). All these soldiers are moving every frame according to rules - think boids / flocking / steering behaviour. For each soldier, to update it's movement I need the X soldiers that are closest to the one I'm processing. What would be the best spatial hierarchy to store them to facilitate calculations like this without too much overhead ? (All entities are updated/moved every frame, so it has to handle dynamic entities very well)

    Read the article

1