Why is std::rotate so fast?

As the commentors already stated, it depends on your Standard Library implementation. But the code that you posted is valid even for forward iterators. As such, it imposes very little requirements (only that these iterators can be incremented and dereferenced). Stepanov’s classic Elements of Programming devotes an entire chapter (10) to rotate and other rearrangement … Read more

Sort a string in lexicographic order python

Do not use lambda functions when there’s builtin ones for the job. Also never use the cmp argument of sorted because it’s deprecated: sorted(s, key=str.lower) or sorted(s, key=str.upper) But that may not keep ‘A’ and ‘a’ in order, so: sorted(sorted(s), key=str.upper) that will and, by the nature of sorted the operation will be very fast … Read more

How to sort 2D array (numpy.ndarray) based to the second column in python? [duplicate]

Use .argsort() it returns an numpy.array of indices that sort the given numpy.array. You call it as a function or as a method on your array. For example, suppose you have import numpy as np arr = np.array([[-0.30565392, -0.96605562], [ 0.85331367, -2.62963495], [ 0.87839643, -0.28283675], [ 0.72676698, 0.93213482], [-0.52007354, 0.27752806], [-0.08701666, 0.22764316], [-1.78897817, 0.50737573], [ … Read more

How to sort using Realm?

You can add an ascending parameter to the sorted method: data = data!.sorted(“date”, ascending: false) This sorts your WorkoutSet using the date field in descending order. Update With Swift 3 and the latest RealmSwift version this has now changed to: data = data!.sorted(byKeyPath: “date”, ascending: false) If you want to evaluate the sort criteria yourself … Read more

How to pass a custom comparator to “sort”?

Define your own <=>, and include Comparable. This is from the Comparable doc: class SizeMatters include Comparable attr :str def <=>(an_other) str.size <=> an_other.str.size end def initialize(str) @str = str end def inspect @str end end s1 = SizeMatters.new(“Z”) s2 = SizeMatters.new(“YY”) s3 = SizeMatters.new(“XXX”) s4 = SizeMatters.new(“WWWW”) s5 = SizeMatters.new(“VVVVV”) s1 < s2 #=> … Read more

Sort a List by enum where enum is out of order

An alternative to using IComparer would be to build an ordering dictionary. var orderMap = new Dictionary<MessageType, int>() { { MessageType.Boo, 0 }, { MessageType.Bar, 1 }, { MessageType.Foo, 2 }, { MessageType.Doo, 3 } }; var orderedList = messageList.OrderBy(m => orderMap[m.MessageType]);

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)