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.
Posts Tagged algorithm
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?