Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
|
akalin
2011/10/17 22:25:25
Thinking about it, a better name for this class wo
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_COMMON_STRING_INDEX_H_ | |
| 6 #define CHROME_COMMON_STRING_INDEX_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 // This class allows strings to be used as floating point numbers (in base 26) | |
|
akalin
2011/10/17 22:25:25
This class is actually closer to fixed-point than
| |
| 12 // in the range of (0..1), so that if there is a sorted array of them and a | |
| 13 // single element is moved, then only that element has to change its index | |
| 14 // value. There will always be a valid value between two adjacent values | |
| 15 // (since infinite less significant digits can be added) and no other values | |
| 16 // need to be adjust to keep the same sorted order. | |
| 17 class StringIndex { | |
| 18 public: | |
| 19 // Create a valid StringIndex if the string matches [A-Z]*[B-Z], | |
|
akalin
2011/10/17 22:25:25
how about using [a-z]*[b-z] instead? I find lower
akalin
2011/10/17 22:25:25
Say something like:
Creates a (possibly invalid)
| |
| 20 // otherwise create an invalid StringIndex. | |
| 21 explicit StringIndex(const std::string& str); | |
| 22 | |
| 23 // Create an invalid StringIndex. | |
| 24 StringIndex(); | |
| 25 | |
| 26 // Returns true iff this was initialized with a string matching [A-Z]*[B-Z]. | |
|
akalin
2011/10/17 22:25:25
I think we can omit this comment (since it's just
| |
| 27 bool IsValid() const; | |
| 28 | |
|
akalin
2011/10/17 22:25:25
add a comment:
// Ordering functions.
| |
| 29 // Returns true iff other is a lexicographically smaller StringIndex than | |
|
akalin
2011/10/17 22:25:25
The comment is incorrect (backwards). Something l
| |
| 30 // this. | |
| 31 bool LessThan(const StringIndex& other) const; | |
| 32 | |
| 33 // Return true iff other has the same value. | |
|
akalin
2011/10/17 22:25:25
// Returns true iff |*this| = |other| (i.e., |*thi
| |
| 34 bool Equal(const StringIndex& other) const; | |
| 35 | |
| 36 // this.LessThan(other) must hold. Returns a StringIndex x such that LessThan( | |
|
akalin
2011/10/17 22:25:25
Actually we should relax the precondition to just
| |
| 37 // x) holds, and x.LessThan(other) holds. | |
| 38 StringIndex CreateBetween(const StringIndex& other) const; | |
| 39 | |
| 40 // Returns a StringIndex x such that x.LessThan(*this) holds. | |
|
akalin
2011/10/17 22:25:25
Returns a StringOrdinal x such that x < |*this|.
| |
| 41 StringIndex CreateBefore() const; | |
| 42 | |
| 43 // Returns a StringIndex x such that LessThan(x) holds. | |
|
akalin
2011/10/17 22:25:25
// Returns a StringOrdinal x such that |*this| < x
| |
| 44 StringIndex CreateAfter() const; | |
| 45 | |
| 46 std::string ToString() const; | |
| 47 | |
| 48 // Use of copy constructor and default assignment for this class is allowed. | |
| 49 | |
| 50 private: | |
| 51 std::string string_index_; | |
| 52 bool is_valid_; | |
| 53 }; | |
| 54 #endif // CHROME_COMMON_STRING_INDEX_H_ | |
| OLD | NEW |