Click button to edit
Sorting: Sort Big File with Record Class
Shows how to sort a big file using a record class
If you need to sort a really big file (20Mb and more) you have the BigFileSorter
Implements External Sorting (wikipedia)
The Sorter will split the file in blocks, write them to temp files, and finally join all in a sorted file
SortingWithRecord.cs
// OrdersTab must be IComparable<OrdersTab>
// We recommend to split in blocks between 1 and 40 Mb
var sorter = new BigFileSorter<OrdersTab>(10*1024*1024); // 10 Mb blocks
sorter.Sort("unsorted.txt", "sorted.txt");
OrdersTab.cs
[DelimitedRecord("\t")]
public class OrdersTab
: IComparable<OrdersTab>
{
public int OrderID;
public string CustomerID;
public int EmployeeID;
public DateTime OrderDate;
[FieldConverter(ConverterKind.Date, "ddMMyyyy")]
public DateTime RequiredDate;
[FieldNullValue(typeof (DateTime), "2005-1-1")]
public DateTime ShippedDate;
public int ShipVia;
public decimal Freight;
#region IComparable<OrdersTab> Members
public int CompareTo(OrdersTab other)
{
return this.OrderID.CompareTo(other.OrderID);
}
#endregion
}