SortedList Collection 
Author Message
 SortedList Collection

Does anyone have any experience/feedback on the performance of a SortedList
collection in comparison with other collection types. I'm currently
implementing a container class derived from IList and containing a
SortedList object to hold my user-defined point type. I'm mapping the calls
exposed by IList to the appropriate SortedList method. My objects are being
indexed by an int field within the user-defined class that will be unique
for the collection ( see a summary of what I'm trying to do below). I want
my collection to behave as a list indexed by the int field and randomly
accessed by this indexed value while hiding the key/value mapping from the
user. What I'm trying to avoid is a large gap in elements and the wasted
memory when there is a large jump in the indexed value.  Also, I want to be
able to emumerate this list in the indexed order, something that a hashtable
does not allow. I guess I'm attempting similar to the set collection type in
STL. Any suggestions??

class MyPoint : IComparable...
{
    int pointNumber;  // indexed by this field.
    double x;
    double y;
    string desc;

    ......

Quote:
}

class MyPointList : IList
{
    SortedList theList;

    // IList implementation and other methods:
    ....

Quote:
}



Mon, 23 May 2005 03:28:36 GMT  
 SortedList Collection
http://www.codeproject.com/CSharp/sets.asp

Take a look at the SortedSet.  It will probably do exactly what you want it
to do, rather than forcing the workaround you are attempting.

Search and add operations using a SortedList (the basis for the SortedSet)
take O(log(n)) time.  Enumerating the entire contents takes O(n) time.  So
either way, you aren't going to take much of a hit, though for very, very
large data sets, it will be slower than a Hashtable implementation.  But
then again, if you need to enumerate in order, SortedList is probably a much
better solution for you.

If you are only dealing with a few thousand or a few tens of thousands of
objects, O(1) vs. O(log(n)) is unlikely to make a noticable difference.


Quote:
> Does anyone have any experience/feedback on the performance of a
SortedList
> collection in comparison with other collection types. I'm currently
> implementing a container class derived from IList and containing a
> SortedList object to hold my user-defined point type. I'm mapping the
calls
> exposed by IList to the appropriate SortedList method. My objects are
being
> indexed by an int field within the user-defined class that will be unique
> for the collection ( see a summary of what I'm trying to do below). I want
> my collection to behave as a list indexed by the int field and randomly
> accessed by this indexed value while hiding the key/value mapping from the
> user. What I'm trying to avoid is a large gap in elements and the wasted
> memory when there is a large jump in the indexed value.  Also, I want to
be
> able to emumerate this list in the indexed order, something that a
hashtable
> does not allow. I guess I'm attempting similar to the set collection type
in
> STL. Any suggestions??

> class MyPoint : IComparable...
> {
>     int pointNumber;  // indexed by this field.
>     double x;
>     double y;
>     string desc;

>     ......
> }

> class MyPointList : IList
> {
>     SortedList theList;

>     // IList implementation and other methods:
>     ....
> }



Tue, 24 May 2005 04:05:19 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Odd problem with System.Collections.SortedList

2. Collections.SortedList

3. A collection inside a collection inside a collection...

4. SortedList, searching for items efficiently

5. deriving from SortedList?

6. SortedList with duplicate items?

7. SortedList sorted by value.

8. SortedList!!

9. Please Help with SortedList!!!

10. SortedList, Why Parenthesis instead of Brackets?

11. SortedList Key as DateTime Class?

 

 
Powered by phpBB® Forum Software