private IParent( IUnion <TLeft, TRight> union, TFunctor <TRight> .THead <TLeft> .IParent <Either <TLeft, TRight> > eitherFunctor) : this( union, new Monad <TLeft, TRight> .TParent <E>(union), eitherFunctor, new Applicative <TLeft, TRight> .TParent <E>(union) ) { }
private IParent( IUnion <TLeft, TRight> union, TMonad <TRight> .THead <TLeft> .IParent <E> eitherMonad, TFunctor <TRight> .THead <TLeft> .IParent <Either <TLeft, TRight> > eitherFunctor, TApplicative <TRight> .THead <TLeft> .IParent <E> applicative ) { _union = union; _eitherMonad = eitherMonad; _eitherFunctor = eitherFunctor; _applicative = applicative; }
public void Traverse <TFunctor>() where TFunctor : ITraversalFunctor, new() { TFunctor functor = new TFunctor(); functor.TraversalStarted(this); foreach (var child in this.children) { child.Traverse <TFunctor>(); } functor.TraversalFinished(); }
/// <summary> /// Main sort function /// </summary> /// <param name="container">A container of the type you declared when declaring</param> /// <param name="valueFunction"> /// A delegate which returns the value for comparison when given a container value /// </param> public void Sort(TContainer container, TFunctor valueFunction) { if (container.Count == 0) { return; } // Setup container areas this._sortSize = container.Count; this._sortArea1 = new SortEntry[this._sortSize]; this._sortArea2 = new SortEntry[this._sortSize]; // Perform alpha pass to count var prevValue = valueFunction(container[0]); var needsSorting = false; var u = 0; foreach (var item in container) { // get sort value var val = valueFunction(item); // cheap check to see if needs sorting (temporal coherence) if (!needsSorting && (((IComparable <System.UInt32>)val).CompareTo(prevValue) < 0)) { needsSorting = true; } // Create a sort entry SortEntry ne; ne.Value = item; ne.Key = val; this._sortArea1[u++] = ne; // increase counters for (var p = 0; p < this._passCount; ++p) { this._counters[p, _getByte(p, val)]++; } prevValue = val; } // early exit if already sorted if (!needsSorting) { return; } // Sort passes this._src = this._sortArea1; this._dest = this._sortArea2; for (var p = 0; p < this._passCount - 1; ++p) { _sortPass(p); // flip src/dst var tmp = this._src; this._src = this._dest; this._dest = tmp; } // Final pass finalPass(this._passCount - 1, prevValue); // Copy everything back for (var c = 0; c < this._sortSize; c++) { container[c] = this._dest[c].Value; } }