Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Unified Diff: src/list-inl.h

Issue 6265002: Adding SearchableList for implementing a list with fast search capability. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/globals.h ('K') | « src/list.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/list-inl.h
===================================================================
--- src/list-inl.h (revision 6372)
+++ src/list-inl.h (working copy)
@@ -201,6 +201,65 @@
}
+template<typename T, class P>
+void SearchableList<T, P>::Add(const T& element) {
+ is_sorted_ = false;
+ List<T, P>::Add(element);
+}
+
+
+template<typename T, class P>
+void SearchableList<T, P>::AddAll(const List<T, P>& other) {
+ is_sorted_ = false;
+ List<T, P>::AddAll(other);
+}
+
+
+template<typename T, class P>
+Vector<T> SearchableList<T, P>::AddBlock(T value, int count) {
+ is_sorted_ = false;
+ return List<T, P>::AddBlock(value, count);
+}
+
+
+template<typename T, class P>
+bool SearchableList<T, P>::Contains(const T& elm) {
+ if (is_sorted_) {
+ return ContainsSorted(elm);
+ }
+ return List<T, P>::Contains(elm);
+}
+
+
+template<typename T, class P>
+bool SearchableList<T, P>::Contains(const T& elm, bool ensure_sorted) {
+ if (ensure_sorted) {
+ Sort(); // Will only sort if not already sorted.
+ }
+ return List<T, P>::Contains(elm);
+}
+
+
+template<typename T, class P>
+void SearchableList<T, P>::Sort() {
+ if (!is_sorted_) {
+ List<T, P>::Sort(comparator_);
+ is_sorted_ = true;
+ }
+}
+
+
+template<typename T, class P>
+bool SearchableList<T, P>::ContainsSorted(const T& elm) {
+ typedef int (*RawComparer)(const void*, const void*);
+ return (NULL != bsearch(&elm,
+ List<T, P>::data(),
+ List<T, P>::length(),
+ sizeof(T),
+ reinterpret_cast<RawComparer>(comparator_)));
+}
+
+
} } // namespace v8::internal
#endif // V8_LIST_INL_H_
« src/globals.h ('K') | « src/list.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698