我目前正在处理具有多个(重新发生)闹钟的闹钟。从一组闹钟中获取第一个闹钟时间
我使用安装了Microsoft IoT的树莓派和UWP(C#)进行布局和底层算法。
我遇到的问题是检索下一个闹钟时间。
伪代码:
Select nextAlarm()
For all alarms a
if (((a.time >= now.time AND a.repeatDay == now.DayOfWeek)
OR a.repeatDay > now.DayOfWeek) AND a.dateTime < currentAlarm.dateTime)
currentAlarm = a;
然而这将需要O(n)的时间为每一个报警功能a.repeatDay> now.DayOfWeek不是一个简单的功能(如果当天是星期三和下一个闹钟是星期一,该功能不起作用)。
我在问的是如何以上述函数的工作方式(最好快于O(n))存储报警,或者如何存储解决问题的重复日期。
目前使用SQLite.net-PCL包
报警和RepeatDay类:
public class Alarm
{
[PrimaryKey, AutoIncrement]
public long Id { get; set; }
[NotNull]
public string Name { get; set; }
[NotNull]
public DateTime Time { get; set; }
[NotNull]
public int Repeat { get; set; }
public Alarm(string name, DateTime time, RepeatWeek repeat)
{
this.Name = name;
this.Time = time;
this.Repeat = repeat;
}
}
public class RepeatWeek
{
int repeat = 0;
public static implicit operator int(RepeatWeek w)
{
return w.repeat;
}
public void setDay(DayOfWeek w)
{
repeat |= 1 << (int)w;
}
public void removeDay(DayOfWeek w)
{
repeat &= ~(1 << (int)w);
}
public DayOfWeek getNext(DayOfWeek d, bool inclToday = false)
{
throw new NotImplementedException();
return DayOfWeek.Monday; //Needs work
}
}
你只是想要下一个预定警报? – maccettura
是的,我目前被困在重复的日子里 – Boe007
为什么不直接勾选勾号并获得最低值? – maccettura