Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 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_ORDINAL_H_ | |
| 6 #define CHROME_COMMON_STRING_ORDINAL_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 // A StringOrdinal represents a specially-formatted string that can be used | |
| 12 // for ordering. The StringOrdinal class has an unbounded dense strict total | |
| 13 // order, which mean for any StringOrdinals a, b and c: | |
| 14 // a < b and b < c implies a < c (transitivity); | |
|
akalin
2011/10/18 17:59:27
Please preserve bullets and newlines around them l
| |
| 15 // exactly one of a < b, b < a and a = b holds (trichotomy); | |
| 16 // if a < b, there is a StringOrdinal x such that a < x < b (density); | |
| 17 // there are StringOrdinals x and y such that x < a < y (unboundedness). | |
| 18 // This means that when StringOrdinal is used for sorting a list, if | |
|
akalin
2011/10/18 17:59:27
extra space after bullets and before this paragrap
| |
| 19 // any item changes its position in the list, only its StringOrinal value | |
| 20 // has to change to represent the new order, all the other older values can stay | |
|
akalin
2011/10/18 17:59:27
"order, all" -> "order, and all"
| |
| 21 // the same. | |
| 22 class StringOrdinal { | |
| 23 public: | |
| 24 // Create a StringOrdinal from the given string. It may be valid or invalid. | |
| 25 explicit StringOrdinal(const std::string& str); | |
|
akalin
2011/10/18 17:59:27
str -> string_ordinal
| |
| 26 | |
| 27 // Create an invalid StringOrdinal. | |
| 28 StringOrdinal(); | |
| 29 | |
| 30 bool IsValid() const; | |
| 31 | |
|
akalin
2011/10/18 17:59:27
Add comment saying all other functions can only be
| |
| 32 // Ordering Functions | |
| 33 | |
| 34 // Returns true iff |*this| < |other| | |
|
akalin
2011/10/18 17:59:27
period at end
| |
| 35 bool LessThan(const StringOrdinal& other) const; | |
| 36 | |
| 37 // Return true iff |*this| == |other| (ie this->LessThan(other) and | |
|
akalin
2011/10/18 17:59:27
ie -> i.e.,
| |
| 38 // other.LessThan(*this) are both false). | |
| 39 bool Equal(const StringOrdinal& other) const; | |
| 40 | |
| 41 // Given |*this| != |other|, returns a StringOrdinal x such that | |
| 42 // min(|*this|, |other|).LessThan(x) holds, and | |
|
akalin
2011/10/18 17:59:27
use min(...) < ... < max(...) like in my suggested
| |
| 43 // x.LessThan(max(|*this|,|other|) holds. It is an error to call | |
| 44 // this function with |*this| == |other| | |
|
akalin
2011/10/18 17:59:27
period at end.
| |
| 45 StringOrdinal CreateBetween(const StringOrdinal& other) const; | |
| 46 | |
| 47 // Returns a StringOrdinal x such that x < |*this|. | |
| 48 StringOrdinal CreateBefore() const; | |
| 49 | |
| 50 // Returns a StringOrdinal x such that |*this| < x. | |
| 51 StringOrdinal CreateAfter() const; | |
| 52 | |
| 53 std::string ToString() const; | |
|
akalin
2011/10/18 17:59:27
// It is guaranteed that a StringOrdinal construct
| |
| 54 | |
| 55 // Use of copy constructor and default assignment for this class is allowed. | |
| 56 | |
| 57 private: | |
| 58 std::string string_index_; | |
|
akalin
2011/10/18 17:59:27
rename this variable to string_ordinal_
| |
| 59 bool is_valid_; | |
| 60 }; | |
| 61 #endif // CHROME_COMMON_STRING_ORDINAL_H_ | |
| OLD | NEW |