@@ -36,10 +36,55 @@ namespace lsst {
36
36
namespace qserv {
37
37
namespace loader {
38
38
39
+
40
+ // / &&&
41
+ class CompositeKey {
42
+ public:
43
+ CompositeKey (uint64_t ki, std::string const & ks) : kInt (ki), kStr (ks) {}
44
+ CompositeKey (uint64_t ki) : CompositeKey(ki, " " ) {}
45
+ CompositeKey (std::string const & ks) : CompositeKey(0 , ks) {}
46
+ CompositeKey (CompositeKey const & ck) : CompositeKey(ck.kInt , ck.kStr ) {}
47
+ CompositeKey () : CompositeKey(0 , " " ) {}
48
+ ~CompositeKey () = default ;
49
+
50
+ static uint64_t maxIntVal () const { return UINT64_MAX; }
51
+
52
+ CompositeKey& operator =(CompositeKey const & other) {
53
+ kInt = other.kInt ;
54
+ kStr = other.kStr ;
55
+ }
56
+
57
+ bool operator <(CompositeKey const & other) const {
58
+ if (kInt < other.kInt ) return true ;
59
+ if (kInt > other.kInt ) return false ;
60
+ if (kStr < other.kStr ) return true ;
61
+ return false ;
62
+ }
63
+
64
+ bool operator >(CompositeKey const & other) const {
65
+ return other < *this ;
66
+ }
67
+
68
+ bool operator =(CompositeKey const & other) const {
69
+ return (kInt == other.kInt ) && (kStr == other.kStr );
70
+ }
71
+
72
+ uint64_t kInt ;
73
+ std::string kStr ;
74
+ };
75
+
39
76
// / Class for storing the range of a single worker.
40
77
// / This is likely to become a template class, hence lots in the header.
41
78
// / It tries to keep its state consistent, _min < _max, but depends on
42
- // / other classes to eventually get the correct values for _min and _max
79
+ // / other classes to eventually get the correct values for _min and _max.
80
+ // /
81
+ // / When new workers are activated, they need placeholder values for
82
+ // / for their ranges, as the new worker will have no keys. increment(...)
83
+ // / and decrement(...) try to create reasonable key values for the ranges
84
+ // / but true ranges cannot be established until the worker and its
85
+ // / right neighbor (if there is one) each have at least one key. The worker
86
+ // / ranges should eventually reach the master, then the other workers
87
+ // / and clients.
43
88
class StringRange {
44
89
public:
45
90
using Ptr = std::shared_ptr<StringRange>;
@@ -50,51 +95,11 @@ class StringRange {
50
95
51
96
~StringRange () = default ;
52
97
53
- void setAllInclusiveRange () {
54
- _min = " " ;
55
- _unlimited = true ;
56
- setValid ();
57
- }
58
-
59
- bool setMin (std::string const & val) {
60
- if (not _unlimited && val >= _maxE) {
61
- _min = decrementString (_maxE);
62
- return false ;
63
- }
64
- _min = val;
65
- return true ;
66
- }
67
-
68
- bool setMax (std::string const & val, bool unlimited=false ) {
69
- _unlimited = unlimited;
70
- if (unlimited) {
71
- if (val > _maxE) { _maxE = val; }
72
- return true ;
73
- }
74
- if (val < _min) {
75
- _maxE = incrementString (_min);
76
- return false ;
77
- }
78
- _maxE = val;
79
- return true ;
80
- }
98
+ void setAllInclusiveRange ();
81
99
82
- bool setMinMax (std::string const & vMin, std::string const & vMax, bool unlimited=false ) {
83
- _unlimited = unlimited;
84
- if (!unlimited && vMin > vMax) {
85
- return false ;
86
- }
87
- _unlimited = unlimited;
88
- if (_unlimited) {
89
- _min = vMin;
90
- _maxE = std::max (vMax, _min); // max is irrelevant at this point
91
- } else {
92
- _min = vMin;
93
- _maxE = vMax;
94
- }
95
- setValid ();
96
- return true ;
97
- }
100
+ bool setMin (CompositeKey const & val);
101
+ bool setMax (CompositeKey const & val, bool unlimited=false );
102
+ bool setMinMax (CompositeKey const & vMin, CompositeKey const & vMax, bool unlimited=false );
98
103
99
104
bool setValid () {
100
105
_valid = (_min <= _maxE );
@@ -142,19 +147,26 @@ class StringRange {
142
147
// / Return a string that would slightly follow the value of the input string 'str'
143
148
// / appendChar is the character appended to a string ending with a character > 'z'
144
149
static std::string incrementString (std::string const & str, char appendChar=' 0' );
150
+ // / Return a CompositeKey slightly higher value than 'key'.
151
+ static CompositeKey increment (CompositeKey const & key, char appendChar=' 0' );
145
152
146
153
// Return a string that would come slightly before 'str'. 'minChar' is the
147
154
// smallest acceptable value for the last character before just erasing the last character.
148
155
static std::string decrementString (std::string const & str, char minChar=' 0' );
149
-
156
+ // / Return a CompositeKey slightly higher lower than 'key'.
157
+ static CompositeKey decrement (CompositeKey const & str, char minChar=' 0' );
150
158
151
159
friend std::ostream& operator <<(std::ostream&, StringRange const &);
152
160
153
161
private:
154
162
bool _valid{false }; // /< true if range is valid
155
163
bool _unlimited{false }; // /< true if the range includes largest possible values.
164
+ CompositeKey _min; // /< Smallest value = ""
165
+ CompositeKey _maxE; // /< maximum value exclusive
166
+ /* &&&
156
167
std::string _min; ///< Smallest value = ""
157
168
std::string _maxE; ///< maximum value exclusive
169
+ */
158
170
159
171
};
160
172
0 commit comments