Back from a brief break, we pick up this week by finishing up the “modifying sequence operations” with some gems like RandomShuffle
and go through the “partitions” category with functions like Partition
and IsPartitioned
. These are all solid algorithms with a lot of potential uses, so read on to see how to use them with iterators and for the source code that implements them!
Posts Tagged algorithm
Continuing the series this week we’ll delve into the iterator functions that modify the sequence. This includes handy tools like Copy
, SwapRanges
, and Transform
. Of course this is all done without creating any garbage! Read on to see how and for the full source code.
Last week’s article introduced the concept of iterators as an alternative to the GC-heavy IEnumerable
. Today’s article expands the iterator library to include a bunch of more functions to make it useful. Think of these like the extension functions in System.Linq
: Any
, IndexOf
, etc. These have all been tailored to iterators and none of them will create any garbage whatsoever.
One of C#’s most unique features is its SQL-style LINQ syntax. It’s a powerful and expressive way to treat data structures like a database and perform all kinds of actions on them. LINQ can also be used without the SQL-style syntax via various extension methods of IEnumerable<T>
defined in the System.Linq
namespace. Due to C#’s extension method feature, we’re free to add on our own LINQ-style functions to extend its power. Today’s article introduces some extension methods to do just that. Read on for the source code and power up your LINQ!
Today’s article is both a reminder to optimize your algorithms and data structures before your code and a demonstration of the payoff you’ll get by doing so. By choosing the most effective algorithm and data structure to solve your problem you’ll reap huge rewards in performance. A 10x, 100x, or even bigger boost is easily attainable.
The XOR swap algorithm is an old programming trick. I’ve never personally seriously entertained using it, even in C, but myths abound that it is somehow faster than simple swapping via a temporary variable. Is it fast or just fancy?