0

I am struggling a little bit to find a nice data representation for a fairly typical scheduling app. The requirements which mess things up a bit is that there are two parties each who have an arbitrary availability daily and there are courses which are offered more or less at fixed times (though exceptions can occur here as well) independent of whether there are two parties available at that timing or not.

As one of the challenges later will be to find available providers for the scheduled courses, I was wondering whether a quick and elegant way could be to simply store a weekly availability pattern for these in a 64-bit integer with a kind of bit-mask.

My rationale is that essentially, every day has 24 hours (< 2^5) and splitting the day into 10 minute intervals there are 144 slots per day (much less than 2^8). Therefore, every person could get a weekly schedule with every day being an 8 bit availability mask for that day (7 x 8bit = 56 bit, less than a 64 bit int).

Filtering and identifying of potential users can very quickly and simply be done by converting any potential appointments into the same kind of mask and then just doing a bitwise operation to only select candidates which are available there without bothering about further rules etc.

What I am wondering is what the reasons are why I don't see much more filtering happening on bit-level as it seems to be fairly straight forward and I'm guessing will hopefully actually even end up being more elegant than a more verbose and explicit logic, any thoughts/ideas?

4

1 回答 1

3

过早优化的典型案例。先让你的程序运行起来,只有当它很慢时,你才应该开始考虑使用按位运算来优化它。您应该真正开始以尽可能最简洁的方式实现它,例如通过使用一个向量或布尔值列表,它们不限于 64 的任意长度。

例如,您可以使用numpy带有dtype=bool. 这可能比手动编码的位向量稍微不那么紧凑,但是您可以免费获得所有逻辑操作(您也可以使用类似 的运算符|, ^, & and ~),而且您可以拥有几乎无限的大小,允许切片、索引等。

于 2013-10-22T19:59:28.877 回答