public virtual void DoWork( IEnumerable <T> source, Action <T> longFunction) { var enumerator = source.GetEnumerator(); enumerator.MoveNext(); Lot <Thread> threads = new XLinkedListLot <Thread>(); foreach (var computation in this.computations) { var current = enumerator.Current; computation(current); var ts = new XLinkedList <Thread>(); ts.AddTail(new Thread(() => longFunction(current))); ts.Head?.Start(); threads = this.rotator.Rotate(ts, 1); if (!enumerator.MoveNext()) { break; } } foreach (var t in threads) { t.Join(); } enumerator.Dispose(); }
public virtual void Order( Tree <T> tree) { var linkedList = new XLinkedList <T>(); var iterations = (int)(tree.Count / (double)this.numberOfSkips + 1); var subtractor = 0; while (subtractor < this.numberOfSkips) { for (var i = 0; i < iterations; ++i) { var amountToSkip = (this.numberOfSkips * (i + 1)) - (subtractor + 1); linkedList.AddTail( FirstOrDefault( Skip( tree, amountToSkip))); } ++subtractor; } this.currentTree = new XLinkedListLot <T>(linkedList); }
public virtual void Surge( Lot <IDisposable> disposables) { if (disposables == null) { return; } var dependencies = new XLinkedList <List <object> >(); foreach (var disposable in disposables) { dependencies.AddTail(new List <object>()); var dd = disposable.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic); var dToSurge = new List <IDisposable>(); foreach (var field in dd) { var value = field.GetValue(disposable); dependencies.Tail?.Add(value); if (field.FieldType == typeof(IDisposable)) { dToSurge.Add((IDisposable)value); } } this.Surge(new ListLot <IDisposable>(dToSurge)); // ReSharper disable once ImpureMethodCallOnReadonlyValueField this.martyr.BringToGod(disposables); var ll = this.illuminator.Illumine < LinkedListLot <IDisposable> >(dependencies); this.illuminator.Illumine <IDisposable>(ll); } }
public virtual Lot <T> Act( Tree <T> tree, IEnumerable <Action <T> > actions) { var orderer = this.treeOrderer; if (orderer == null) { return(tree); } if (actions == null) { orderer.Order(tree); return(orderer.OrderedTree); } orderer.Order(tree); var actionEnumerator = actions.GetEnumerator(); var linkedList = new XLinkedList <T>(); foreach (var value in orderer.OrderedTree) { actionEnumerator.MoveNext(); actionEnumerator.Current?.Invoke(value); linkedList.AddTail(value); } actionEnumerator.Dispose(); return(new XLinkedListLot <T>( linkedList)); }
public virtual IEnumerable <T> Innovate <T>( Lot <T>[] lots, Func <T, BigInteger> valueChooser) { if (lots == null || lots.Length < 1) { yield break; } var enumerators = new XLinkedList <IEnumerator <T> >(); foreach (var lot in lots) { if (lot == null) { continue; } enumerators.AddTail(lot.GetEnumerator()); } while (enumerators.Head?.MoveNext() ?? false) { BigInteger leastValue = long.MaxValue; BigInteger maximalValue = 0; var leastItem = default(T); var maximalItem = default(T); foreach (var enumerator in Skip( enumerators, 1)) { enumerator.MoveNext(); var value = valueChooser(enumerator.Current); if (value < leastValue) { leastValue = value; leastItem = enumerator.Current; } if (value > maximalValue) { maximalValue = value; maximalItem = enumerator.Current; } } yield return(leastItem); yield return(maximalItem); } }
protected virtual int deepen( TreeNode <T> node, int currentDepth) { if (node.Nodes.Count < 1) { return(currentDepth); } ++currentDepth; var depths = new XLinkedList <int>(); foreach (var n in node.Nodes) { depths.AddTail(this.deepen(n, currentDepth)); } return(Max(depths)); }
public Lot <Action <T> > PeekComputations( BigInteger numberToPeek) { var ll = new XLinkedList <Action <T> >(); var enumerator = this.computations.GetEnumerator(); enumerator.MoveNext(); for (var i = 0; i < numberToPeek; ++i) { ll.AddTail(enumerator.Current); if (!enumerator.MoveNext()) { break; } } enumerator.Dispose(); return(new XLinkedListLot <Action <T> >(ll)); }
public virtual Lot <object> Process( IEnumerable <object> references) { var ll = new XLinkedList <object>(); var lld = new XLinkedList <IDisposable>(); foreach (var reference in references) { if (reference is IDisposable) { lld.AddTail((IDisposable)reference); continue; } ll.AddTail(reference); } // ReSharper disable once ImpureMethodCallOnReadonlyValueField this.martyr.BringToGod(new XLinkedListLot <IDisposable>(lld)); return(new XLinkedListLot <object>(ll)); }
public virtual bool Judge( Lot <T> lot, Action <T> learn) { var reflection = new Reflection <T>(lot, this.absolution); var hashCodes = new XLinkedList <int>(); var isKnowledge = true; foreach (var item in reflection.Reflect(learn)) { var hashCode = item.GetHashCode(); if (hashCodes.Contains(hashCode)) { isKnowledge = false; break; } hashCodes.AddTail(item.GetHashCode()); } return(isKnowledge); }
public virtual Tuple <LiberatedObject, LiberatedObject> Slice( LiberatedObject anObject, int slicePoint) { if (anObject == null) { return(Tuple.Create <LiberatedObject, LiberatedObject>( null, null)); } var dc = anObject.DependencyCount; if (slicePoint > dc) { return(Tuple.Create <LiberatedObject, LiberatedObject>( null, null)); } var oneDeps = new XLinkedList <object>(); for (var i = 0; i < slicePoint; ++i) { oneDeps.AddTail(anObject[i]); } var twoDeps = new XLinkedList <object>(); for (var i = slicePoint; i < dc; ++i) { twoDeps.AddTail(anObject[i]); } return(Tuple.Create( new LiberatedObject(oneDeps), new LiberatedObject(twoDeps))); }
public virtual Lot <T> Darken <T>( IEnumerable <T> source, BigInteger limiter) { var hashCodes = new XLinkedList <int>(); // hash codes should be longs var darkenedCollection = new XLinkedList <T>(); foreach (var item in source) { var hashCode = item.GetHashCode(); if (Any( hashCodes, hc => Math.Abs(hashCode - hc) < limiter)) { continue; } hashCodes.AddTail(hashCode); darkenedCollection.AddTail(item); } return(new XLinkedListLot <T>( darkenedCollection)); }
public virtual TimeSpan TimeWorked( DateTime beginning, DateTime end) { var r = this.runner; var allTimes = this.allTimes(); var timeWorked = TimeSpan.Zero; var timesInRange = new XLinkedList <DateTime>(); long timeCounter = 0; foreach (var time in allTimes) { if (time < beginning) { ++timeCounter; if (timeCounter < allTimes.Count) { continue; } goto checkIfClockedInBeforeFirst; } if (time > end) { if (timesInRange.Count < 1 && timeCounter % 2 == 1) { // clocked in at beginning timesInRange.AddTail(beginning); } if (timesInRange.Count % 2 == 1) { // clocked in at end timesInRange.AddTail(end); } break; } checkIfClockedInBeforeFirst: if (timesInRange.Count < 1 && timeCounter % 2 == 1) { // clocked in at start of range timesInRange.AddHead(beginning); } if (timeCounter >= allTimes.Count) { break; } timesInRange.AddTail(time); } var e = ((ICollection <DateTime>)timesInRange) .GetEnumerator(); while (e?.MoveNext() ?? false) { var inTime = e.Current; if (!e.MoveNext()) { var now = DateTime.Now; r?.Run <TimeProvider>(provider => { now = provider.Now(); }); if (end.Date > now) { if (inTime < now) { timeWorked += now - inTime; } break; } timeWorked += end.Date - inTime; break; } var outTime = e.Current; timeWorked += outTime - inTime; } e.Dispose(); return(timeWorked); }
public virtual void Handle( TimestampsUi ui, HomeNavUi homeNavUi, StatisticsUi statsUi) { var r = this.runner; const byte one = 1; r?.Run <UiReaderWriter>(uiRW => { uiRW.Write( homeNavUi, () => { homeNavUi.ActiveKeyLabel = NavKeyLabels.Timestamps; }); }); var showCurrent = true; r?.Run <SettingsHolder>(settings => { showCurrent = settings.ShowCurrent; }); var now = DateTime.Now; var start = DateTime.Today; r?.Run <TimeProvider>(provider => { now = provider.Now(); start = now.Date; }); var end = start.AddDays(one); if (showCurrent) { r?.Run <DateCalculator>( calc => { start = calc.StartOfWeek(); end = calc.EndOfWeek().AddDays(one); }); goto findAndSetTimesInRange; } r?.Run <UiReaderWriter>(uiRW => { start = uiRW.Read( statsUi, () => statsUi.StartDate); end = uiRW.Read( statsUi, () => statsUi.EndDate) .AddDays(1); }); findAndSetTimesInRange: r?.Run < TimestampReader, Lotter, EnumerableSplitter, UiReaderWriter>( (reader, lotter, splitter, uiRW) => { var allTimes = reader.ReadAll(); var timesInRange = new XLinkedList <DateTime>(); foreach (var time in allTimes) { if (time < start) { continue; } if (time > end) { continue; } timesInRange.AddTail(time); } bool firstIn, lastIn; if (timesInRange.Count < one) { firstIn = false; lastIn = false; goto checkAdd; } firstIn = this.isInTime( timesInRange.Head); lastIn = this.isInTime( timesInRange.Tail); checkAdd: var inNow = allTimes.Count % two == one; var oddTimesInRange = timesInRange.Count % two == one; if (oddTimesInRange) { if (inNow && firstIn) { if (now > end.AddDays(one)) { // was clocked in at end of range timesInRange.AddTail(end); } // clocked in currently, do nothing goto afterCheckClockedIn; } if (firstIn) { // clocked in at end of week timesInRange.AddTail(end.Date); goto afterCheckClockedIn; } // clocked out now but was clocked in at start of week timesInRange.AddHead(start.Date); goto afterCheckClockedIn; } if (timesInRange.Count > zero) { if (!firstIn) { timesInRange.AddHead(start.Date); } if (lastIn && end < now) { timesInRange.AddTail(end.Date); } } afterCheckClockedIn: var splitTimesThisWeek = splitter.Split( timesInRange, two); var inTimes = splitTimesThisWeek[zero]; var uiTimesIn = lotter.Materialize( EnumerableHelpers.Select( inTimes, this.formatTimestamp)); uiRW.Write( ui, () => { ui.InTimes = uiTimesIn; }); var outTimes = splitTimesThisWeek[one]; var uiTimesOut = lotter.Materialize( EnumerableHelpers.Select( outTimes, this.formatTimestamp)); uiRW.Write( ui, () => { ui.OutTimes = uiTimesOut; }); r.Run <EnumerableSplicer>( splicer => { var splicedTimes = splicer.Splice( new[] { inTimes, outTimes }); short indexer = zero; DateTime currentInTime = default,