public static Func <DateTime, int> CreateDateIndexer <T>(this ITerm range, Dictionary <DateTime, int> dateToIndexTable, Func <DateTime, T> construct, out T[] dates) { var viewDays = Convert.ToInt32(range.GetLength().TotalDays); var start = range.Start.Date; dates = new T[viewDays]; for (var i = 0; i < viewDays; i++) { var date = start.AddDays(i); dateToIndexTable[date] = i; dates[i] = construct(date); dates[i].SaftyInvoke <IIndexable>(d => { d.Index = dateToIndexTable[date]; }); } var indexer = new Func <DateTime, int>(date => { if (!dateToIndexTable.ContainsKey(date)) { return(-1); } return(dateToIndexTable[date]); }); return(indexer); }
public static bool[] ConvertToCell(this IEnumerable <Term> terms, ITerm boundary, int cellUnit, Func <Term, bool> cellResult, Action <Term> additionalLooping) { //#if DEBUG // var sw = Stopwatch.StartNew(); //#endif var capacity = Convert.ToInt32(boundary.GetLength().TotalMinutes) / cellUnit; var cells = new bool[capacity]; var boundaryStart = boundary.Start; var boundaryCapacity = cells.Length; foreach (var item in terms) { if (item.Start >= boundary.End) { continue; } var content = cellResult(item); var endIndex = item.End.GetIndex(boundaryStart, cellUnit, boundaryCapacity, 0); for (var i = item.Start.GetIndex(boundaryStart, cellUnit, boundaryCapacity, 0); i < endIndex; i++) { cells[i] = content; } if (additionalLooping != null) { additionalLooping(item); } } //#if DEBUG // sw.Stop(); // Console.WriteLine("{0}", sw.Elapsed.Seconds); //#endif return(cells); }