R
Robert Zurer
Assuming that I have created a strongly typed collection and overridden the
appropriate methods, i.e. this[], Add, Insert etc., so that a sort order is
maintained, it's still very possible for a property of the
'ListMemberObject' which is instrumental in the sort to be modified
unbeknownst to the list thereby defeating the sort.
One way to keep the list sorted is to add a 'ParentList' property to the
ListMemberObject and notify that ParentList to sort itself in every set
method of the list object. That would repeat code everywhere and is
extremely yucky.
I've looked at a few implementations of creating a sorted list, most notably
http://www.codeproject.com/useritems/SortableList.asp
but the problem is not addressed.
In a related vein. If I want to use ArrayList.BinarySearch for the express
purpose of only adding unique values,
public override int Add(object o)
{
int result = -1;
if(o == null)throw new ArgumentNullException();
IComparer idComparer = new IDComparer();
Sort(idComparer);
//if I call this here the application dies a slow and painful death with
a large list
//if I don't call it I'm not absolutely sure my list is sorted properly
int binSrch = this.BinarySearch(idComparer );
if(binSrch < 0)
{
base.Insert(~binSrch, o);
result = ~binSrch;
}
return result;
}
What to do?
TIA
Robert Zurer
appropriate methods, i.e. this[], Add, Insert etc., so that a sort order is
maintained, it's still very possible for a property of the
'ListMemberObject' which is instrumental in the sort to be modified
unbeknownst to the list thereby defeating the sort.
One way to keep the list sorted is to add a 'ParentList' property to the
ListMemberObject and notify that ParentList to sort itself in every set
method of the list object. That would repeat code everywhere and is
extremely yucky.
I've looked at a few implementations of creating a sorted list, most notably
http://www.codeproject.com/useritems/SortableList.asp
but the problem is not addressed.
In a related vein. If I want to use ArrayList.BinarySearch for the express
purpose of only adding unique values,
public override int Add(object o)
{
int result = -1;
if(o == null)throw new ArgumentNullException();
IComparer idComparer = new IDComparer();
Sort(idComparer);
//if I call this here the application dies a slow and painful death with
a large list
//if I don't call it I'm not absolutely sure my list is sorted properly
int binSrch = this.BinarySearch(idComparer );
if(binSrch < 0)
{
base.Insert(~binSrch, o);
result = ~binSrch;
}
return result;
}
What to do?
TIA
Robert Zurer