sorting

Sorting contents of a file in place in linux

Hi all, I have a file which has multiple columns, whitespace separated. e.g: data1 data2 data3 data4 val1 val2 val3 val4 I need to sort the file based on values in different columns, i.e sometime based on value of column 1 sometime based on value of col2 ...

WPF : CollectionViewSource displaying grouped by Property

In Xaml, suppose I have a CollectionViewSource who's source is set to observable collection of objects of type Order: public class Order { public int ContractID { get; set; } public double? Price { get; set; } public OrderSide Side { get; set; } } public...

counting duplicates in a sorted sequence using command line tools

I have a command (cmd1) that greps through a log file to filter out a set of numbers. the numbers are in random order, so i use sort -gr to get a reverse sorted list of numbers. there may be duplicates within this sorted list. I need to find the count for each unique number in that list. For e.g. if the output of cmd1 is 100 100 ...

Hibernate: Sorting by a field from a linked table if foreign key is null

Lets say I have two tables - "Cat" and "Cat owner" that are linked with many-to-one like this: <class name="com.example.Cat" table="cat"> ... <many-to-one name="owner" class="com.example.CatOwner" column="owner_id" not-null="false" insert="true" update="true" cascade="none" lazy="false"/> </class> Now I w...

Optimal way to sort a txt file in Java

I've got a CSV file that I'm processing using the opencsv library. So I can read in each line. The particular transformation I need to do requires me to sort that file first before I run through it with the main portion of my java file. e.g. 5423, blah2, blah 5323, blah3, blah 5423, blah4, blah 5444, blah5, blah 5423, blah6, blah s...

How do I sort alphabetically in Python?

Python sorts by byte value by default, which means é comes after z and other equally funny things. What is the best way to sort alphabetically in Python? Is there a library for this? I couldn't find anything. Preferrably sorting should have language support so it understands that åäö should be sorted after z in Swedish, but that ü shoul...

SortedList that just takes IComparable<T>

I have an interface IScriptItem that implements IComparable<IQueueItem>. In my eyes it would seem enough to have IComparable items in order to have a sorted anything. But all I can find is Dictionaries, Hashtables and SortedLists that are actually SortedTrees. What I'm looking for is a sorted generic list that takes IComparables. Am I l...

Error in std::list::sort with custom comparator (expected primary-expression before ')' token)

Hi all! The title is the main question. The exact scenario (I am 'using namespace std;'): void SubstringMiner::sortByOccurrence(list<Substring *> & substring_list) { list::sort(substring_list.begin(), substring_list.end(), Substring::OccurrenceComparator); } This is the comparator definition: class Substring { // ... class...

How can one sort an NSMutableArray of NSMutableArrays containing NSStrings?

Is there an easy way to sort an NSMutableArray of NSMutableArrays containing NSStrings? I am sure that there must be an easy method for doing this but I can't seem to find it. To Clarify I want to sort the first array alphabetically by the NSString at index 3 of the sub array. ...

Need help with STL sort algorithm

I'm having some troubles with using the std::sort algorithm here. I was reading that you can just overload the less than operator to sort classes, but I have been getting all sorts of errors. I have also tried using a functor as you can see in the example I made below. I was hoping somebody could see what I'm doing wrong here. #include...

Does python have a sorted list?

By which I mean a structure with: O(log n) complexity for x.push() operations O(log n) complexity to find an element O(n) complexity to compute list(x) which will be sorted I also had a related question about performance of list(...).insert(...) which is now here. ...

How to sort a LinkedHashMap by its value class's field?

I use the following lines to sort a LinkedHashMap, but not all items are sorted, anything wrong ? LinkedHashMap<String,PatternData> statisticsMap; // fill in the map ... LinkedHashMap<String,PatternData> sortedStatisticsMap=new LinkedHashMap<String,PatternData>(); // Sort it by patternData's average ArrayList<PatternData> statis...

how to sort numeric vectors?

Now, there are lots of ordered numeric vectors(about 50 dimension). Each dimension is a integer between 0~200. I want to sort them to ensure the similar vectors in the same bucket, all vectors in adjacent buckets have also a similarity to a certain extent. e.g. <1,24,25,78,9> and <2,24,24,78,9> should be in same bucket(bucket number is 0...

Sort dead hyperlinks in Excel with VBA?

Hi All The title says it: I have an excel Sheet with an column full of hyperlinks. Now I want that an VBA Script checks which hyperlinks are dead or work and makes an entry into the next columns either with the text 404 Error or active. Hopefully someone can help me because I am not really good at VB. EDIT: I found @ http://www.utte...

Is there a way to order an associative array by how the keys are inserted with PHP?

Here's an example of what I mean: I have an array: array('type'=>'text', 'class'=>'input', 'name'=>'username', 'id'=>'username', 'value'=>'', 'size'=>'30', 'rows'=>'', 'cols'=>''); Then, I loop through it like so: $input = '<input '; foreach($input_array as $key => $value) { if(...

How do I programatically sort through media?

I have 6 server with a aggregated storage capacity of 175TB all hosting different sorts of media. A lot of the media is double and copies stored in different formats so what I need is a library or something I can use to read the tags in the media and decided if it is the best copy available. For example some of my media is japanese conte...

Sorting objects in an array by a field value in JavaScript

Say I have an array of JS objects: var objs = [ { first_nom: 'Lazslo',last_nom: 'Jamf' }, { first_nom: 'Pig', last_nom: 'Bodine' }, { first_nom: 'Pirate', last_nom: 'Prentice' } ]; How can I sort them by the value of last_nom in JavaScript. I know about sort(a,b) but that only seems to work on stri...

How do I sort an array in Scala?

I can see there's a Sorting object with a quickSort method on it. Can someone provide a code example of using it, sorting an array of object of arbitrary type? It looks like I need to pass in an impl of the Orderable trait, but I am unsure of the syntax. Also, I would prefer answers doing this the 'scala way'. I know I can just use a J...

Custom sorting problem, always force 0 to back of ascending order?

Premise This problem has a known solution (shown below actually), I'm just wondering if anyone has a more elegant algorithm or any other ideas/suggestions on how to make this more readable, efficient, or robust. Background I have a list of sports competitions that I need to sort in an array. Due to the nature of this array's populati...

Sort NSArray of date strings or objects

I have an NSArray that contains date strings like this: "Thu, 21 May 09 19:10:09 -0700" I need to sort the NSArray by date. I thought about converting the date string to an NSDate object first, but got stuck there on how to sort by the NSDate object. Thanks. ...