Chromium Code Reviews| Index: src/utils.h |
| diff --git a/src/utils.h b/src/utils.h |
| index be8d0a7698a792b513c9f590dddeb6e9406fd475..e3e000fcf28f3c2c17a281c9601ab8fae73e316c 100644 |
| --- a/src/utils.h |
| +++ b/src/utils.h |
| @@ -83,6 +83,23 @@ static inline T RoundUp(T x, int m) { |
| } |
| +template <typename T> |
| +static int Spaceship(const T& a, const T& b) { |
|
Erik Corry
2008/11/13 11:45:43
The reasoning behind this name is a little opaque
Christian Plesner Hansen
2008/11/13 11:58:37
http://en.wikipedia.org/wiki/Spaceship_operator
W
|
| + if (a == b) |
| + return 0; |
| + else if (a < b) |
| + return -1; |
| + else |
| + return 1; |
| +} |
| + |
| + |
| +template <typename T> |
| +static int PointerSpaceship(const T* a, const T* b) { |
| + return Spaceship<T>(*a, *b); |
| +} |
| + |
| + |
| // Returns the smallest power of two which is >= x. If you pass in a |
| // number that is already a power of two, it is returned as is. |
| uint32_t RoundUpToPowerOf2(uint32_t x); |
| @@ -318,6 +335,18 @@ class Vector { |
| return Vector<T>(result, length_); |
| } |
| + void Sort(int (*cmp)(const T*, const T*)) { |
| + typedef int (*RawComparer)(const void*, const void*); |
| + qsort(start(), |
| + length(), |
| + sizeof(T), |
| + reinterpret_cast<RawComparer>(cmp)); |
| + } |
| + |
| + void Sort() { |
| + Sort(PointerSpaceship<T>); |
| + } |
| + |
| // Releases the array underlying this vector. Once disposed the |
| // vector is empty. |
| void Dispose() { |