小编Lak*_*aky的帖子

查找包含给定时间点的间隔的最快方法

我需要创建基于时间的"计划结构",使用以下方法:

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)

c# algorithm datetime intervals

-4
推荐指数
1
解决办法
740
查看次数

标签 统计

algorithm ×1

c# ×1

datetime ×1

intervals ×1