hi everybody,
does anybody know of a way to remove an item from a .NET sortedset when it falls out of order?
Before you jump to tell me that a sorted set cannot fall out of order, all that needs to happen is for an object in the sorted set to have a parameter (by which the set is sorted) altered.
For example, imagine if we have a Person class with a modifiable 'Name' field, and a sortedset<person> that contains many people, and is sorted by Name.
[0]"April"
[1]"Bob"
[2]"Mary"
[3]"Zelda"
If we change the name of item 0 (April) to "Zoe", it will remain at position 0:
[0]"Zoe"
[1]"Bob"
[2]"Mary"
[3]"Zelda"
What I have tried:
I tried to get the items to fire an event so that when these fields changed ( e.g. Name), the sortedset would find the item, remove it, and then reinsert it, So it should be in the right order. This doesn't work, though, because the sortedset cannot find/remove items when it is out of order: presumably its binary search method stops working. I can't find a method which lets you remove items from a specific index.
I have also tried the RemoveWhere() method like so, but it still doesn't find the items:
public void RemoveSafe(T removeMe)
{
RemoveWhere(a => a == removeMe);
}
an alternate solution, of course, is to remove an item, modify it, then add it back in. Unfortunately my program & sorting criteria is a bazillion times more complex than the Person example above, and this solution would make it very messy indeed...
So, to reiterate:
does anybody know of a way to remove an item from a sorted set when it falls out of order?
Other ideas also welcome :)
Thanks!