forked from viewfinderco/viewfinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhotoSelection.h
59 lines (48 loc) · 1.59 KB
/
PhotoSelection.h
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
57
58
59
// Copyright 2013 Viewfinder. All rights reserved.
// Author: Spencer Kimball.
#ifndef VIEWFINDER_PHOTO_SELECTION_H
#define VIEWFINDER_PHOTO_SELECTION_H
#import <unordered_set>
#import "WallTime.h"
struct PhotoSelection {
int64_t photo_id;
int64_t episode_id;
WallTime timestamp;
PhotoSelection()
: photo_id(0), episode_id(0), timestamp(0) {
}
PhotoSelection(int64_t pi, int64_t ei, WallTime t = 0)
: photo_id(pi),
episode_id(ei),
timestamp(!t ? WallTime_Now() : t) {
}
};
ostream& operator<<(ostream& os, const PhotoSelection& ps);
struct PhotoSelectionHash {
size_t operator()(const PhotoSelection& ps) const {
// TODO(spencer): we need a hashing module.
const size_t kPrime = 31;
size_t result = kPrime + int(ps.photo_id ^ (ps.photo_id >> 32));
return result * kPrime + int(ps.episode_id ^ (ps.episode_id >> 32));
}
};
struct PhotoSelectionEqualTo {
bool operator()(const PhotoSelection& a, const PhotoSelection& b) const {
return a.photo_id == b.photo_id && a.episode_id == b.episode_id;
}
};
struct SelectionLessThan {
bool operator()(const PhotoSelection& a, const PhotoSelection& b) const {
return a.timestamp < b.timestamp;
}
};
typedef std::unordered_set<PhotoSelection,
PhotoSelectionHash,
PhotoSelectionEqualTo> PhotoSelectionSet;
typedef vector<PhotoSelection> PhotoSelectionVec;
// Convert photo selection set to vector.
PhotoSelectionVec SelectionSetToVec(const PhotoSelectionSet& s);
#endif // VIEWFINDER_PHOTO_SELECTION_H
// local variables:
// mode: c++
// end: