Note that there are some explanatory texts on larger screens.

plurals
  1. POArrayList sort method
    primarykey
    data
    text
    <p>A friend and I are writing some software (as a side project) and are having trouble with ArrayLists.</p> <p>We're storing a collection of instances of a custom object (containing a DateTime and two strings) in an ArrayList. Once we've stored all of the entries in the ArrayList, we're sorting them by DateTime. The problem is, that we're having to store of 100,000 instances of the object, which means that the built in sort method is taking a very long time - we clocked it at over an hour, at one point.</p> <p>The speed of the sort isn't so much of an issue, but I was just wondering whether there was a better way to sort elements in an ArrayList than using the built in sort method. Although I guess not, based on the fact that the built in .net stuff will be highly optimised.</p> <p>Note: We're using ArrayLists because of the middleware we've chosen to use for generating PDF reports, based on the content of the ArrayList. I guess, if we had the chance to move over to List&lt;> then the sort methods would be better. Or would they?</p> <p>Edit:</p> <p>Based on requests for source code, I'll post some. But I'm not sure how much I can provide that isn't obvious.</p> <pre><code>public class DataObject : ICompareable { private DateTime timeStamp; private string description; private string detail; public DataObject (DataTime inTimeStamp, string inDescription, string inDetail) { this.timeStamp = inTimeStamp; this.description = inDescription; this.detail = inDetail; } int IComparable.CompareTo(object that) { DataObject myThat = (DataObject)that; return this._timestamp.CompareTo(myThat._timestamp); } } // .... // ArrayList dataList = new ArrayList(); for (int i = 0; i &lt; database.Packets.Count; i++) { dataList.Add(new DataObject(database.Packet(i).GetTimeStamp(), database.Packet(i).GetDescription(), database.Packet(i).GetDetail()); } // ... same as the above, but for other data // ... types (all parse to strings when pulled // ... from the database dataList.Sort(); </code></pre> <p>That's about it, largely. We're pulling data from several places in an SQLCEME3.5 database (we're using .net 3.5, so we can't use LINQ), placing them in an ArrayList of objects and using that object ArrayList further down the pipe.</p> <p>We want to get all the records from multiple places in the database (some are packets, some are strings (prompts), some are other types, all parse down to strings) and sort them all by time stamp. We want all the data interspersed - a packet followed by some string value, followed by some object value, if that's the order that they were stored/raised in.</p> <p>We have read-only access to the database, so I don't think that using the database, itself to sort them would be a good idea (or even possible). That being said, I am really new to SQL - never used it before this project. Can that be done?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload