summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/wtf/ListHashSet.h
diff options
context:
space:
mode:
Diffstat (limited to 'JavaScriptCore/wtf/ListHashSet.h')
-rw-r--r--JavaScriptCore/wtf/ListHashSet.h50
1 files changed, 44 insertions, 6 deletions
diff --git a/JavaScriptCore/wtf/ListHashSet.h b/JavaScriptCore/wtf/ListHashSet.h
index 3172943..2f75c33 100644
--- a/JavaScriptCore/wtf/ListHashSet.h
+++ b/JavaScriptCore/wtf/ListHashSet.h
@@ -1,6 +1,5 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
- * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -34,7 +33,7 @@ namespace WTF {
// order - iterating it will always give back values in the order
// in which they are added.
- // In theory it would be possible to add prepend, insertAfter, insertBefore,
+ // In theory it would be possible to add prepend, insertAfter
// and an append that moves the element to the end even if already present,
// but unclear yet if these are needed.
@@ -91,10 +90,13 @@ namespace WTF {
const_iterator find(const ValueType&) const;
bool contains(const ValueType&) const;
- // the return value is a pair of an interator to the new value's location,
+ // the return value is a pair of an iterator to the new value's location,
// and a bool that is true if an new entry was added
pair<iterator, bool> add(const ValueType&);
+ pair<iterator, bool> insertBefore(const ValueType& beforeValue, const ValueType& newValue);
+ pair<iterator, bool> insertBefore(iterator it, const ValueType&);
+
void remove(const ValueType&);
void remove(iterator);
void clear();
@@ -102,6 +104,7 @@ namespace WTF {
private:
void unlinkAndDelete(Node*);
void appendNode(Node*);
+ void insertNodeBefore(Node* beforeNode, Node* newNode);
void deleteAllNodes();
iterator makeIterator(Node*);
const_iterator makeConstIterator(Node*) const;
@@ -309,7 +312,10 @@ namespace WTF {
const_iterator& operator--()
{
ASSERT(m_position != m_set->m_head);
- m_position = m_position->m_prev;
+ if (!m_position)
+ m_position = m_set->m_tail;
+ else
+ m_position = m_position->m_prev;
return *this;
}
@@ -381,7 +387,6 @@ namespace WTF {
std::swap(m_head, other.m_head);
std::swap(m_tail, other.m_tail);
m_allocator.swap(other.m_allocator);
- return *this;
}
template<typename T, typename U>
@@ -470,6 +475,23 @@ namespace WTF {
}
template<typename T, typename U>
+ pair<typename ListHashSet<T, U>::iterator, bool> ListHashSet<T, U>::insertBefore(iterator it, const ValueType& newValue)
+ {
+ typedef ListHashSetTranslator<ValueType, HashFunctions> Translator;
+ pair<typename ImplType::iterator, bool> result = m_impl.template add<ValueType, NodeAllocator*, Translator>(newValue, m_allocator.get());
+ if (result.second)
+ insertNodeBefore(it.node(), *result.first);
+ return std::make_pair(makeIterator(*result.first), result.second);
+
+ }
+
+ template<typename T, typename U>
+ pair<typename ListHashSet<T, U>::iterator, bool> ListHashSet<T, U>::insertBefore(const ValueType& beforeValue, const ValueType& newValue)
+ {
+ return insertBefore(find(beforeValue), newValue);
+ }
+
+ template<typename T, typename U>
inline void ListHashSet<T, U>::remove(iterator it)
{
if (it == end())
@@ -533,6 +555,22 @@ namespace WTF {
}
template<typename T, typename U>
+ void ListHashSet<T, U>::insertNodeBefore(Node* beforeNode, Node* newNode)
+ {
+ if (!beforeNode)
+ return appendNode(newNode);
+
+ newNode->m_next = beforeNode;
+ newNode->m_prev = beforeNode->m_prev;
+ if (beforeNode->m_prev)
+ beforeNode->m_prev->m_next = newNode;
+ beforeNode->m_prev = newNode;
+
+ if (!newNode->m_prev)
+ m_head = newNode;
+ }
+
+ template<typename T, typename U>
void ListHashSet<T, U>::deleteAllNodes()
{
if (!m_head)