summaryrefslogtreecommitdiff
path: root/p2pvr/daemon/schedulers/bitDumbScheduler.cpp
blob: 1c1010543553ca39f0caa1b5f141e6ef9b01af52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "../schedules.h"

namespace P2PVR {
class TheBitDumbScheduler : public EpisodeGroup {
	public:
		TheBitDumbScheduler(const Episodes & eps) :
			episodes(eps)
		{
		}

	protected:
		void SelectShowings()
		{
			SelectShowings(episodes.begin(), 1);
		}

	private:
		void SelectShowings(Episodes::const_iterator e, uint64_t complexityLevel)
		{
			if (e != episodes.end()) {
				complexityLevel *= (*e)->showings.size();
				if (complexityLevel > 2 << 16) {
					auto current = showings.size();
					for (EpisodesIter ne = e; ne != episodes.end(); ne++) {
						for (const auto & s : (*ne)->showings) {
							showings.push_back(s);
							if (SuggestWithFeedback(showings) & 0x1) {
								break;
							}
							showings.pop_back();
						}
					}
					showings.resize(current);
				}
				else {
					EpisodesIter ne = e;
					ne++;
					for (const auto & s : (*e)->showings) {
						showings.push_back(s);
						SelectShowings(ne, complexityLevel);
						showings.pop_back();
					}
				}
			}
			else {
				Suggest(showings);
			}
		}

		mutable Showings showings; // working set
		const Episodes episodes;
};

NAMEDFACTORY("BitDumb", TheBitDumbScheduler, EpisodeGroupFactory);
}