Project structure structure for merging meeting schedules

I was asked to create a data structure for meeting schedules, and then combine them. For example, if person A has a meeting from 9:00 to 10:00, and person B has a meeting from 9:30 to 11:30, then the combined employment slot is from 9:00 to 11:30.

I created classes for Person, and this class has a collection of collection objects. The Meeting class has a start time [hh: mm] in a 24-hour format so I can easily compare.

class Person { String name; Collection<Meeting> meetings; } class Meeting{ int hh, mm; int duration; // duration will be in minutes from where we can get the end time. } 

I want to know which data structure will be most effective for merging. One way is to use a sorted ArrayList collection.

Any best design is appreciated.

+4
source share
3 answers

As shown in @Anonymouse, you can use 96 bits, i.e. 12 bytes to represent the day, so a 30-minute meeting starting at 1:00 in the morning will be represented as 110,000, and you can use simple | for all rooms.

Time O (n) Memory O (12n) bytes. That would be more theoretical.


Assembly meeting [start time per minute, end time per minute].

Combining two meetings (Sa and Sb) in Sc when overlapping

Sc [minimum (SA-start, SB-start), maximum (end SA, SB-end)] and save the combined collections in the collection. If they do not overlap, you can save them separately.

We know that total minutes per day = 24 * 60 = 1440 If you have a 15-minute block, it becomes 24 * 60/15 = 96 (less than 1 byte)

So, you need 2 bytes per schedule, that is, the beginning, the end of the byte.

Time O (n) Memory O (2n) bytes


Both approaches will not work if you have to delete the appointment later. To do this, you should definitely post all the original meeting schedules separately.

+2
source

Since it is unrealistic to schedule meetings with time intervals of less than 15 minutes, I would agree to ... a long . 64 bits per day, this is enough for 16 hours; I do not need it. Or use two longs / three ints for a full day if you want.

Merging is an operation | . For large time intervals, I can shift or them, and then check if the bits have not been canceled as the time the meeting started. This high-cost data structure will process any index only because of low-level operations. The CPU cache can correspond to the schedules of hundreds of days / users.

+2
source

This is a classic task scheduling problem.

-1
source

Source: https://habr.com/ru/post/1384186/


All Articles