-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsorted_set_key.hpp
40 lines (31 loc) · 1014 Bytes
/
sorted_set_key.hpp
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
#ifndef __SORTED_SET_KEY_HPP__
#define __SORTED_SET_KEY_HPP__
#include <vector>
/*
* Element in the <set> of the sorted set. Contains a score and a non-owning
* pointer to the member.
*/
class sorted_set_key
{
public:
struct compare
{
bool operator()(const sorted_set_key&, const sorted_set_key&) const;
};
sorted_set_key(double score, double lex_largest=false);
sorted_set_key(double score, const std::vector<unsigned char>* ptr);
double score() const;
// Throws if member_ptr_ is null.
const std::vector<unsigned char>& member() const;
// Constructs a new key with a new score but the same
// pointer to member.
sorted_set_key with_new_score(double score) const;
private:
double score_;
const std::vector<unsigned char>* member_ptr_;
// Flag to set whether the null string should be lexicographically
// the 'largest'. This is useful when finding an inclusive upper_bound
// based only on score.
bool lex_largest_;
};
#endif