Chromium Code Reviews| Index: Source/wtf/TableSet.h |
| diff --git a/Source/core/platform/Task.h b/Source/wtf/TableSet.h |
| similarity index 66% |
| copy from Source/core/platform/Task.h |
| copy to Source/wtf/TableSet.h |
| index fe0270a8ec78113c954aa5a1fd5d2758d23a89eb..b394c5b8869040d8c9074df42517c1c34d99a8a1 100644 |
| --- a/Source/core/platform/Task.h |
| +++ b/Source/wtf/TableSet.h |
| @@ -28,30 +28,51 @@ |
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| -#ifndef Task_h |
| -#define Task_h |
| +#ifndef WTF_TableSet_h |
| +#define WTF_TableSet_h |
| -#include "wtf/Functional.h" |
| -#include <public/WebThread.h> |
| +#include "wtf/NonCopyingSort.h" |
| -namespace WebCore { |
| +#include <algorithm> |
| -class Task : public WebKit::WebThread::Task { |
| +namespace WTF { |
| + |
| +template<typename T> |
| +class TableSet { |
|
eseidel
2013/05/22 00:40:14
This needs to be more scary. And I would add a he
|
| public: |
| - explicit Task(const Closure& closure) |
| - : m_closure(closure) |
| + typedef bool (*Predicate)(const T&, const T&); |
| + |
| + explicit TableSet(Predicate compareLess) |
| + : m_compareLess(compareLess) |
| + , m_values(0) |
| + , m_size(0) |
| { |
| } |
| - virtual void run() OVERRIDE |
| + void init(T values[], size_t size) |
| { |
| - m_closure(); |
| + ASSERT(isEmpty()); |
| + m_values = values; |
| + m_size = size; |
| + nonCopyingSort(m_values, m_values + m_size, m_compareLess); |
| } |
| + bool contains(const T& value) |
| + { |
| + ASSERT(!isEmpty()); |
|
eseidel
2013/05/22 00:40:14
Do you also want to ASSERT That value is never nul
abarth-chromium
2013/05/22 00:58:25
It's a const reference. There's no way for a cons
|
| + return std::binary_search(m_values, m_values + m_size, value, m_compareLess); |
| + } |
| + |
| + bool isEmpty() { return !m_size; } |
|
eseidel
2013/05/22 00:40:14
This is really isInitialized, no?
abarth-chromium
2013/05/22 00:58:25
Yep.
|
| + |
| private: |
| - Closure m_closure; |
| + Predicate m_compareLess; |
| + T* m_values; |
| + size_t m_size; |
| }; |
| -} // namespace WebCore |
| +} // namespace WTF |
| + |
| +using WTF::TableSet; |
| -#endif // Task_h |
| +#endif |