我需要创建基于时间的"计划结构",使用以下方法:
Void addTask(DateTime startTime, int durationInMinutes, TaskObject myObj)
{
// add TaskObject to calendar structure
}
List<TaskObject> getRunningTasks (DateTime startTime, DateTime endTime)
{
//this procedure have to efficiently return list of running tasks in specified time frame
}
List<TaskObject> getRunningTasks (DateTime exactTime)
{
return getRunningTaks(exactTime,exactTime);
}
Run Code Online (Sandbox Code Playgroud)
我有大约60k个TaskObjects需要计算,需要在几小时和几分钟内重新计算(getRunningTasks将被调用大约400k次)
现在我使用:
public Dictionary<long, Dictionary<int, Dictionary<int, List< TaskObject>>>> scheduleTable;
Run Code Online (Sandbox Code Playgroud)
scheduleTable [dayInTicks] [小时] [分钟]
我将所有匹配的任务添加到每个小时和分钟,在哪里安排它们.
来自DrKoch的想法
public class TaskList
{
private SortedDictionary<DateTime, TaskObject> startTimes;
private SortedDictionary<DateTime, TaskObject> endTimes;
private SortedSet<DateTime> startTimeIndexes;
private SortedSet<DateTime> endTimeIndexes;
public …Run Code Online (Sandbox Code Playgroud)