Question

creating a very simple scheduling app

I am asking the user to tell me what day(s) they work, and whether on a given day they work morning, lunch, or evening

so, for a given user her data could be one or all of the points in the following matrix

        morning    lunch    evening
mon
tue
wed
thr
fri
sat
sun 

I need to quickly be able to retrieve this information so that I can alert the user that it's time to go to work. I will have many users.

I don't care about specific dates, or time. just the discrete days 1 through 7 and the 3 slots within each day. Certainly, there are many possible combinations.

I am considering how to store this information. And I am wondering if a bitmask is appropriate / feasible / the 'way to go with something like this' ? How would you approach this?

thanks!

Was it helpful?

Solution

While a bitmask will definitely work (employing 7 days X 3 shifts = 21 bits), my experience with these things is they always need modification. That is, a night shift is added, or shifts are otherwise changed.

Given that, I'd suggest building some flexibility into your app. Combine the bitmask idea with a table that defines what the bits represent. That way you can redefine and modify as you please. If you add a shift, just add a record to the definition table and update each employee's mask.

OTHER TIPS

To answer your second question: unless you have millions of rows, a bitmask is not going to be a huge performance advantage (your bottleneck will still be network I/O) and probably a premature optimization. That said, you will be able to store all of the user's options in a single 32 bit integer.

Don't bother with a bitmask. Do something simple now (like perhaps a normalized DB schema!), and optimize for performance later if you start measuring problems.

If they can only choose one option per day, you can pack the data into 14 bits of a 16-bit int. Or if they can choose multiple options per day, you could pack it into 21 bits of a 32-bit int.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top