Link to home
Start Free TrialLog in
Avatar of Ryan
RyanFlag for United States of America

asked on

Best Ordered List to Use

I have a collection that I want to keep sorted.
Main operation will be to put an object into the list, and take out either the Next or Prev one. (Get the next larger or next smaller item). This will be iterated maybe 500k times.

Count will be up to 5000, of a custom class, already implementing IComparable

What collection should I use? VB.NET 4.0

I just tried SortedSet(of T), but I can't get the index of the newly added item.

I was using a List(of T), and rather than removing, just marking as "Used", but that's annoying.
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

SortedList? Where sort value is key and object is value?
Avatar of Ryan


I omitted that I have 2 sorting values, handled by my custom CompareTo() function.

I couldn't figure out how to get SortedList to handle that.
Hello, I'm curious to follow this solution, but I couldn't figure out how to monitor it without replying. I could swear there used to be a monitor option.

I'm, intrigued by your question and I'm curious as to whether you really need to dynamically remove items or if the solution might involve inserting everything and then enumerting the list with the comparator to walk them in the correct order. Not clear on why you are removing some items, and if that can be done in the enumeration virtually by determining they can be skipped?
Avatar of Ryan


On the left hand side theres a toolbar with share links and I think one is a start to monitor?

In my case, I have a list of items that I'm trying to find sets that have the same sum of 2 properties.   In final tweaking, I'm trying to swap out an item for the next higher (or lower) one.  The initial setup involves selecting by indices of the sorted items too to get an even selection across my distribution.

I've been on other projects, but based on no responses, I think I'll have to write my own wrapper to probably extend List, and either maintain sort on Add(), or just mark as used and use an iterator.
Avatar of Ryan
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ryan


Didn't get any advice, came up with this.