Chromium Code Reviews| Index: chrome/common/string_ordinal.h |
| diff --git a/chrome/common/string_ordinal.h b/chrome/common/string_ordinal.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1fcf3b736ca015a277f819e537c09ff496643cc4 |
| --- /dev/null |
| +++ b/chrome/common/string_ordinal.h |
| @@ -0,0 +1,61 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_COMMON_STRING_ORDINAL_H_ |
| +#define CHROME_COMMON_STRING_ORDINAL_H_ |
| +#pragma once |
| + |
| +#include <string> |
| + |
| +// A StringOrdinal represents a specially-formatted string that can be used |
| +// for ordering. The StringOrdinal class has an unbounded dense strict total |
| +// order, which mean for any StringOrdinals a, b and c: |
| +// a < b and b < c implies a < c (transitivity); |
|
akalin
2011/10/18 17:59:27
Please preserve bullets and newlines around them l
|
| +// exactly one of a < b, b < a and a = b holds (trichotomy); |
| +// if a < b, there is a StringOrdinal x such that a < x < b (density); |
| +// there are StringOrdinals x and y such that x < a < y (unboundedness). |
| +// 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
|
| +// any item changes its position in the list, only its StringOrinal value |
| +// 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"
|
| +// the same. |
| +class StringOrdinal { |
| + public: |
| + // Create a StringOrdinal from the given string. It may be valid or invalid. |
| + explicit StringOrdinal(const std::string& str); |
|
akalin
2011/10/18 17:59:27
str -> string_ordinal
|
| + |
| + // Create an invalid StringOrdinal. |
| + StringOrdinal(); |
| + |
| + bool IsValid() const; |
| + |
|
akalin
2011/10/18 17:59:27
Add comment saying all other functions can only be
|
| + // Ordering Functions |
| + |
| + // Returns true iff |*this| < |other| |
|
akalin
2011/10/18 17:59:27
period at end
|
| + bool LessThan(const StringOrdinal& other) const; |
| + |
| + // Return true iff |*this| == |other| (ie this->LessThan(other) and |
|
akalin
2011/10/18 17:59:27
ie -> i.e.,
|
| + // other.LessThan(*this) are both false). |
| + bool Equal(const StringOrdinal& other) const; |
| + |
| + // Given |*this| != |other|, returns a StringOrdinal x such that |
| + // min(|*this|, |other|).LessThan(x) holds, and |
|
akalin
2011/10/18 17:59:27
use min(...) < ... < max(...) like in my suggested
|
| + // x.LessThan(max(|*this|,|other|) holds. It is an error to call |
| + // this function with |*this| == |other| |
|
akalin
2011/10/18 17:59:27
period at end.
|
| + StringOrdinal CreateBetween(const StringOrdinal& other) const; |
| + |
| + // Returns a StringOrdinal x such that x < |*this|. |
| + StringOrdinal CreateBefore() const; |
| + |
| + // Returns a StringOrdinal x such that |*this| < x. |
| + StringOrdinal CreateAfter() const; |
| + |
| + std::string ToString() const; |
|
akalin
2011/10/18 17:59:27
// It is guaranteed that a StringOrdinal construct
|
| + |
| + // Use of copy constructor and default assignment for this class is allowed. |
| + |
| + private: |
| + std::string string_index_; |
|
akalin
2011/10/18 17:59:27
rename this variable to string_ordinal_
|
| + bool is_valid_; |
| +}; |
| +#endif // CHROME_COMMON_STRING_ORDINAL_H_ |