// Linked list implementation
template <class T> class List
{
public:
List();
~List();
void Append(const T& element);
void RemoveFirst();
void RemoveLast();
void Clear();
bool IsEmpty() const;
T& Front() const;
T& Back() const;
T& Top() const;
T& Bottom() const;
private:
T m_data;
};
template <class T> List<T>::List() : m_data(NULL)
{
}
template <class T> List<T>::~List()
{
while ( !IsEmpty() )
RemoveFirst();
}
template <class T> void List<T>::Append(const T& element)
{
m_data = new T(element);
}
template <class T> void List<T>::RemoveFirst()
{
m_data->RemoveFirst();
}
template <class T> void List<T>::RemoveLast()
{
m_data->RemoveLast();
}
template <class T> void List<T>::Clear()
{
m_data->Clear();
}
template <class T> bool List<T>::IsEmpty() const
{
return m_data == NULL;
}
template <class T> T& List<T>::Front() const
{
assert( m_data != NULL );
return *m_data;
}
template <class T> T& List<T>::Back() const
{
assert( m_data != NULL );
return *(m_data - 1);
}
template <class T> T& List<T>::Top() const
{
assert( m_data != NULL );
return *(m_data - 1 - m_data->GetSize());
}
template <class T> T& List<T>::Bottom() const
{
assert( m_data != NULL );
return *(m_data - 1 - m_data->GetSize() + 1);
}
#endif // LIST_H
<|endoftext|>
// Linked list implementation
template <class K, class V, class Compare = std::less<K>, class Data = HashTable<K, V> >
class HashTableConstIterator
: private Data
{
typedef Data ThisT;
typedef HashTableConstIterator<ThisT, V, Compare, Data> OtherT;
friend class HashTable;
friend class HashTable<K, V>;
public:
HashTableConstIterator() : Data() {}
explicit HashTableConstIterator(const ThisT& iter) : Data(iter) {}
explicit HashTableConstIterator(const OtherT& iter) : Data(iter.begin()) {}
explicit HashTableConstIterator(const typename OtherT::const_iterator& iter)
: Data(iter) {}
template<class OtherK>
explicit HashTableConstIterator(const HashTableConstIterator<OtherK, V, Compare, Data>& iter)
: Data(iter.const_cast_derived()) {}
HashTableConstIterator& operator++()
{
Data::increment();
return *this;
}
HashTableConstIterator operator++(int)
{
HashTableConstIterator old(*this);
Data::increment();
return old;
}
bool operator==(const HashTableConstIterator& other) const
{
return Data::operator==(other);
}
bool operator!=(const HashTableConstIterator& other) const
{
return !(*this == other);
}
bool operator==(const typename Data::const_iterator& other) const
{
return Data::operator==(other);
}
bool operator!=(const typename Data::const_iterator& other) const
{
return !(*this == other);
}
ThisT& operator*() const
{
return Data::operator*();
}
OtherT* operator->() const
{
return Data::operator->();
}
bool operator!() const
{
return !Data::isHashTableEmpty();
}
size_t hash() const
{
return Data::hash();
}
static ptrdiff_t hashOffset()
{
return reinterpret_cast<ptrdiff_t>(this);
}
private:
friend class typename HashTable<K, V>::Iterator;
friend class typename HashTable<K, V>::ConstIterator;
friend class HashTableConstIterator<ThisT, V, Compare, Data>;
friend class HashTable<K, V>;
bool isHashTableEmpty() const
{
return Data::isEmpty();
}
};
} // namespace WTF
using WTF::HashTableConstIterator;
<|endoftext|>
// Linked list implementation
namespace details
{
template< typename T > class slist_impl
{
public:
typedef T value_type;
typedef T& reference;
typedef T* pointer;
slist_impl( slist_impl const& ) = delete;
slist_impl( slist_impl && ) = delete;
~slist_impl() {}
size_t size() const noexcept { return impl_->size(); }
reference operator[]( size_t i ) const noexcept { return impl_->operator[]( i ); }
void push_back( reference item )
{
impl_->push_back( item );
}
reference front() const
{
return impl_->front();
}
pointer data() noexcept { return impl_->data(); }
reference front() noexcept { return impl_->front(); }
reference back() const noexcept { return impl_->back(); }
pointer front() noexcept { return impl_->front(); }
pointer back() const noexcept { return impl_->back(); }
private:
template< typename... Args >
slist_impl( Args&&... args )
: impl_( std::make_unique< impl_type >( std::forward<Args>(args)... ) )
{
}
template< typename Arg >
slist_impl( Arg&& arg )
: impl_( std::make_unique< impl_type >( std::forward<Arg>(arg) ) )
{
}
std::unique_ptr< impl_type > impl_;
};
} // namespace details
/// Defines an object-oriented container
template< typename ... Ts >
class slist : public details::slist_impl< Ts... >
{
public:
/// Constructor
explicit slist( Ts&&... args ) :
details::slist_impl< Ts... >( std::forward<Ts>(args) )
{
}
/// Move constructor
slist( slist&& that ) noexcept :
details::slist_impl< Ts... >( std::move(that) )
{
}
/// Assignment
slist& operator=( slist&& that ) noexcept
{
if( this != &that )
{
using std::swap;
swap( *this, *that );
}
return *this;
}
/// Destructor
~slist()
{
if( impl_.get() != nullptr )
{
auto data = impl_->front();
detail::slist_impl< Ts... >::~impl_type();
swap( data, *impl_ );
}
}
};
} // namespace system
} // namespace make_process_internals
#endif // #ifndef BOOST_PROCESS_DETAIL_LISTS_HPP
<|endoftext|>
// Linked list implementation
#include "MemoryOutStream.h"
#include "StreamAdapter.h"
#include <algorithm>
#ifdef _MSC_VER
# pragma warning (disable : 4756) // assignment operator could not be generated
#endif
namespace Firebird {
//
// MemoryOutStream::Buffer
//
StreamBuffer::Buffer::Buffer(Stream& stream)
: stream(stream), pos(0), size(0), buffer(NULL), length(0)
{
try
{
if (stream.hasData())
{
buffer = (char*) stream.alloc(stream.used());
if (buffer)
{
length = stream.used();
pos = 0;
}
}
}
catch (const Exception&)
{
fb_assert(false);
}
}
StreamBuffer::Buffer::Buffer(const MemoryStream& stream)
: stream(stream), pos(0), size(0), buffer(NULL), length(0)
{
try
{
if (stream.hasData())
{
buffer = (char*) stream.alloc(stream.used());
if (buffer)
{
length = stream.used();
pos = 0;
}
}
}
catch (const Exception&)
{
fb_assert(false);
}
}
StreamBuffer::Buffer::~Buffer()
{
try
{
if (buffer)
{
if (pos)
{
if (length >= pos + size)
{
size -= pos;
memmove(buffer, buffer + pos, size);
pos = 0;
}
else
{
size = 0;
}
}
delete[] buffer;
buffer = NULL;
}
}
catch (const Exception&)
{
fb_assert(false);
}
}
void StreamBuffer::Buffer::setTo(const UCHAR* ptr, FB_SIZE_T len)
{
FB_SIZE_T length = length - pos;
if (ptr && (length == 0 || len == length))
{
pos = 0;
delete[] buffer;
buffer = NULL;
}
if (length)
{
buffer = (char*) stream.alloc(length + 1);
buffer[length] = 0;
memcpy(buffer, ptr, len);
buffer[length + 1] = 0;
pos = length;
}
}
void StreamBuffer::Buffer::reset()
{
pos = 0;
delete[] buffer;
buffer = NULL;
}
//
// MemoryOutStream::Buffer
//
MemoryOutStream::Buffer::Buffer(MemoryStream& stream)
: buffer(NULL), length(0), pos(0), size(stream.size())
{
buffer = new char[size];
stream.addRef();
}
MemoryOutStream::Buffer::Buffer(MemoryStream& stream, size_t initialSize)
: buffer(NULL), length(0), pos(0), size(initialSize)
{
buffer = new char[initialSize];
stream.addRef();
}
MemoryOutStream::Buffer::~Buffer()
{
if (buffer)
{
delete[] buffer;
buffer = NULL;
}
}
void MemoryOutStream::Buffer::reset()
{
pos = 0;
delete[] buffer;
buffer = NULL;
}
void MemoryOutStream::Buffer::add(const UCHAR* ptr, FB_SIZE_T len)
{
FB_SIZE_T length = length - pos;
if (buffer && (length == size || len == length))
{
memcpy(buffer + pos, ptr, len);
pos += len;
return;
}
buffer = (char*) stream.alloc(length + len);
if (buffer)
{
memcpy(buffer, ptr, len);
pos = length;
length += len;
stream.add
// Linked list implementation
class RTCList
{
public:
static uint32_t GetHeapID();
private:
RTCList()
: m_pHead(NULL),
m_pTail(NULL)
{ }
public:
RTCList* m_pHead; /* Pointer to first element */
RTCList* m_pTail; /* Pointer to last element */
};
/////////////////////////////////////////////////////////////////////////////
// Auto-claim helper
// NOTE: We must track lifetime of all RTCList objects before
// they can be destroyed. Using a ScopedCLock on the object for
// some to prevent a dangling pointer.
//
// Usage:
// AutoCLock lock(RTCLock::LOCK_RECURSIVE);
// ListNode* pCurNode = NULL;
// for (;;)
// {
// if (!pCurNode)
// {
// pCurNode = new ListNode;
// if (!pCurNode)
// {
// delete pCurNode;
// pCurNode = NULL;
// break;
// }
// }
// pCurNode->Add(this);
// {
// if (pCurNode->IsAlive())
// {
// break;
// }
// }
// }
// if (!pCurNode)
// {
// pCurNode = new ListNode;
// if (!pCurNode)
// {
// delete pCurNode;
// pCurNode = NULL;
// return;
// }
// }
// delete pCurNode;
// lock.Unlock();
/////////////////////////////////////////////////////////////////////////////
//
// RTCListLink
//
// Purpose:
// The "link" element is used to handle list structure
// gently: types and links to all elements
//
class RTCListLink
{
public:
RTCListLink(ListNode* pObj, ListNode* pOther)
: m_pObj(pObj), m_pNext(pOther)
{ }
ListNode* m_pObj;
ListNode* m_pNext;
};
/////////////////////////////////////////////////////////////////////////////
//
// RTCListUser -- Contains the link and the user data for the list.
// The user data is used for pushing to the list in the specific
// list-id (rtelc).
//
struct RTCListUser
{
int m_id;
void* m_pvUser;
int m_fValid;
};
/////////////////////////////////////////////////////////////////////////////
//
// Abstract list class
class RTCListBase
{
public:
RTCListBase();
virtual ~RTCListBase();
void Add(ListNode* pObj, ListNode* pOther);
void Remove(ListNode* pObj, ListNode* pOther);
int32_t GetCount() const { return m_lCount; }
// Special case:
// (IsWeakType(type)) implies IsPtr (type) == NULL
// IsUnique type implies IsPtr (type) == obj
// (type) does not have the unique flag
bool IsPtr(IType type) const;
int32_t IsWeakType(IType type) const { return m_lWeakType != NULL && m_lWeakType->GetType() == type; }
// Attaching
ListNode* Add(void* pObj, void* pOther);
ListNode* Remove(void* pObj, void* pOther);
ListNode* GetFirst(IType type) const;
ListNode* GetLast(IType type) const;
ListNode* GetPrev(ListNode* pObj, ListNode* pOther) const;
ListNode* GetNext(ListNode* pObj, ListNode* pOther) const;
// Wrappers
void* GetObjPtr(IType type) const;
bool IsPtr(IType type) const;
bool IsUnique(IType type) const;
void* GetValid(IType type) const { return m_fValid != 0 ? m_fValid : GetObjPtr(type); }
// This is a very slow operation. Thus the caller must explicitly
// lock the list when it wishes to access the list after it has
// been locked.
int32_t GetExtraCount() const;
// Fast path
ListNode*
// Linked list implementation
QList<QDomNode> XmlRpcUtil::head;
void XmlRpcUtil::addNode()
{
XmlRpcUtil::head.append(QDomNode());
}
bool XmlRpcUtil::isTail()
{
return XmlRpcUtil::tail.isEmpty();
}
QDomNode XmlRpcUtil::tail()
{
if (isTail()) {
XmlRpcUtil::tail = XmlRpcUtil::head.last();
}
return XmlRpcUtil::tail;
}
bool XmlRpcUtil::isFirst()
{
if (XmlRpcUtil::head.isEmpty()) {
return false;
}
return XmlRpcUtil::head.first().isElement();
}
QDomElement XmlRpcUtil::firstElement()
{
if (isFirst()) {
XmlRpcUtil::head.takeFirst();
return XmlRpcUtil::head.first().toElement();
}
return QDomElement();
}
QDomNode XmlRpcUtil::insertBefore(QDomNode old, QDomElement newEl)
{
old.setAttributes(newEl);
return XmlRpcUtil::insertBefore(old, newEl.cloneNode().toElement());
}
QDomNode XmlRpcUtil::insertAfter(QDomNode old, QDomElement newEl)
{
if (isTail()) {
return XmlRpcUtil::insertAfter(old, newEl.cloneNode().toElement());
}
return XmlRpcUtil::insertAfter(old, newEl.cloneNode().lastChild().toElement());
}
QDomNode XmlRpcUtil::replaceChild(QDomNode old, QDomNode newEl)
{
if (isTail()) {
return XmlRpcUtil::replaceChild(old, newEl.cloneNode());
}
return XmlRpcUtil::replaceChild(old, newEl.cloneNode().toElement());
}
bool XmlRpcUtil::hasSubElement(QDomNode old, QString tagName)
{
QDomNode it = old.lastChild();
while (!it.isNull()) {
if (it.toElement().tagName() == tagName) {
return true;
}
it = it.previousSibling();
}
return false;
}
QDomNode XmlRpcUtil::addTextElement(QDomDocument &doc, QDomElement &el)
{
QDomNode oldEl = XmlRpcUtil::firstElement();
if (hasSubElement(oldEl, "section")) {
QDomElement newEl = doc.createElement("section");
doc.documentElement().replaceChild(oldEl, newEl);
el = newEl;
return oldEl;
} else {
return XmlRpcUtil::insertAfter(oldEl, el.cloneNode());
}
}
QDomNode XmlRpcUtil::addChild(QDomDocument &doc, QDomElement &el)
{
QDomNode oldEl = XmlRpcUtil::firstElement();
if (hasSubElement(oldEl, "subelement")) {
QDomElement newEl = doc.createElement("subelement");
doc.documentElement().replaceChild(oldEl, newEl);
el = newEl;
return oldEl;
} else {
return XmlRpcUtil::insertAfter(oldEl, el.cloneNode());
}
}
QDomElement XmlRpcUtil::removeSubElement(QDomNode oldEl, QString tagName)
{
QDomNode it = oldEl.lastChild();
while (!it.isNull()) {
if (it.toElement().tagName() == tagName) {
QDomNode next = it.nextSibling();
QDomElement tmpEl = it.toElement();
it = oldEl.removeChild(it);
el.replaceChild(tmpEl, new QDomText(el.text()));
return tmpEl;
} else {
it = next;
}
}
return QDomElement();
}
QDomElement XmlRpcUtil::removeChild(QDomNode oldEl, QString tagName)
{
QDomNode it = oldEl.lastChild();
while (!it.isNull()) {
if (it.toElement().tagName() == tagName) {
QDomNode next = it.nextSibling();
QDomElement tmpEl = it.toElement();
it = oldEl.removeChild(it);
el.replaceChild(tmpEl, new QDomText(el.text()));
return tmpEl;
} else {
it = next;
}
}
return QDomElement();
}
void XmlRpcUtil::serialize(QString &s, QDomElement &
// Linked list implementation
#if defined(FX_CODE)
template<class T>
class CFX_LinkedList {
public:
typedef CFX_LinkedListNode<T> Node;
typedef CFX_ListTemplate<Node> List;
typedef typename List::Node_Link DataLink;
typedef typename List::Data Data;
typedef typename List::Link Link;
typedef typename List::Link_Data DataLink_Data;
CFX_LinkedList();
CFX_LinkedList(const T* pHead);
~CFX_LinkedList();
void RemoveLink(Link* pLink);
void InsertLink(Link* pLink, DataLink_Data* pDataLink);
DataLink_Data* GetHeadDataLink();
Link* GetFirstLink() const;
Link* GetNextLink(Link* pLink) const;
bool CanInsert(const T* pLink);
bool Insert(const T* pLink, DataLink_Data* pDataLink);
bool Insert(const T* pLink, Link* pNewLink);
bool Insert(Link* pNewLink, const T* pLink);
T* AddHead(const T* pLink);
void DeleteAllLinks();
void Sort();
void SortAllLinks();
bool IsEmpty();
size_t GetCount() const { return m_Size; }
void Clear();
bool InsertFirst(const T* pLink, const T* pData);
bool InsertFirst(const T* pLink, Link* pNewLink);
bool InsertLast(const T* pLink, const T* pData);
bool InsertLast(const T* pLink, Link* pNewLink);
bool RemoveFirst(const T* pLink);
bool RemoveFirst(Link* pNewLink);
bool RemoveLast(const T* pLink);
bool RemoveLast(Link* pNewLink);
void ClearNodes();
void RemoveAllNodes();
const T* GetHead() const;
const T* GetTail() const;
Link* GetFirstLink() const;
Link* GetLastLink() const;
bool MoveNext(Link* pNewLink);
bool MovePrev(Link* pNewLink);
bool MoveChild(Link* pNewLink);
protected:
void AddToTail(Link* pNewLink, const T* pLink);
void MoveFirstLink(Link* pOldLink);
void MoveLastLink(Link* pLink);
private:
size_t m_Size;
T* m_pHead;
T* m_pLast;
Link* m_pFirstLink;
Link* m_pLastLink;
};
#endif // defined(FX_CODE)
#endif // CORE_FXCRT_CFX_LINKEDLIST_H_
<|endoftext|>
// Linked list implementation
//------------------------------------------------------------------------------
// Increment this object's reference count (it does not
// increment the reference count itself).
template <class T>
void LinkedList<T>::inc()
{
LinkedListNode<T>* next = head;
do
{
next = next->next;
next->next = this;
this->setNext(next);
} while (next);
}
template <class T>
LinkedListNode<T>* LinkedList<T>::removeHead()
{
LinkedListNode<T>* temp = head;
head = head->next;
temp->next = nullptr;
return temp;
}
template <class T>
LinkedListNode<T>* LinkedList<T>::removeHeadNoDelete()
{
LinkedListNode<T>* temp = head;
head = head->next;
temp->next = nullptr;
return temp;
}
template <class T>
LinkedListNode<T>* LinkedList<T>::removeFirst()
{
LinkedListNode<T>* temp = head;
head = head->next;
temp->next = nullptr;
return temp;
}
template <class T>
LinkedListNode<T>* LinkedList<T>::removeFirstNoDelete()
{
LinkedListNode<T>* temp = head;
head = head->next;
temp->next = nullptr;
return temp;
}
template <class T>
LinkedListNode<T>* LinkedList<T>::removeLast()
{
LinkedListNode<T>* temp = head;
head = head->prev;
temp->prev = nullptr;
return temp;
}
template <class T>
LinkedListNode<T>* LinkedList<T>::removeLastNoDelete()
{
LinkedListNode<T>* temp = head;
head = head->prev;
temp->prev = nullptr;
return temp;
}
template <class T>
LinkedListNode<T>* LinkedList<T>::remove(LinkedListNode<T>* deleteNode)
{
LinkedListNode<T>* next;
LinkedListNode<T>* previous;
do
{
next = deleteNode->next;
previous = deleteNode->prev;
deleteNode->prev = previous;
deleteNode->next = next;
deleteNode = next;
} while (deleteNode != head);
return previous;
}
template <class T>
LinkedListNode<T>* LinkedList<T>::take(LinkedListNode<T>* deleteNode)
{
LinkedListNode<T>* next;
LinkedListNode<T>* previous;
do
{
next = deleteNode->next;
previous = deleteNode->prev;
deleteNode->prev = nullptr;
deleteNode->next = next;
deleteNode = next;
} while (deleteNode != head);
return previous;
}
//------------------------------------------------------------------------------
// Non-member operators.
//------------------------------------------------------------------------------
// Assignment
//------------------------------------------------------------------------------
template <class T>
LinkedList<T>& LinkedList<T>::operator=(LinkedList<T>&& other)
{
head = other.head;
other.head = nullptr;
other.previous = nullptr;
other.next = nullptr;
return *this;
}
//------------------------------------------------------------------------------
// Compare List entries
//------------------------------------------------------------------------------
template <class T>
bool LinkedList<T>::operator==(const LinkedList<T>& other) const
{
if (head == other.head)
return true;
else
return false;
}
//------------------------------------------------------------------------------
// Comparison by Reference Count
//------------------------------------------------------------------------------
template <class T>
bool LinkedList<T>::operator==(const LinkedList<T>::RefCountPtr& other) const
{
if (head == other.head)
return true;
else
return false;
}
//------------------------------------------------------------------------------
// Copy List entries
//------------------------------------------------------------------------------
template <class T>
LinkedList<T>& LinkedList<T>::operator=(const LinkedList<T>& other)
{
while (other.head)
{
tail->next = other.tail->next;
tail = tail->next;
}
return *this;
}
//------------------------------------------------------------------------------
// Copy List entries
//------------------------------------------------------------------------------
template <class T>
LinkedList<T>::LinkedList(const LinkedList<T>& other)
// Linked list implementation
class LinkNode {
public:
LinkNode();
LinkNode(std::list<LinkNode*>);
~LinkNode();
LinkNode* remove(LinkNode* node);
LinkNode* swap(LinkNode* node, LinkNode* new_node);
// Return node without removing it.
LinkNode* head() {
LinkNode* old = head_;
head_ = node_;
return old;
}
// Return the number of links in the list.
size_t count() const { return count_; }
private:
LinkNode* node_;
size_t count_;
LinkNode* head_;
};
// List implementation
class LinkList {
public:
LinkList();
~LinkList();
LinkNode* add(LinkNode* node);
LinkNode* remove(LinkNode* node);
LinkNode* swap(LinkNode* node, LinkNode* new_node);
// Return node without removing it.
LinkNode* head() {
LinkNode* old = head_;
head_ = nullptr;
return old;
}
// Return the number of links in the list.
size_t count() const { return count_; }
private:
LinkNode* head_;
size_t count_;
};
// Linked List implementation
class LinkedList {
public:
LinkedList();
~LinkedList();
LinkNode* add(LinkNode* node);
LinkNode* remove(LinkNode* node);
LinkNode* remove_by_index(int index);
LinkNode* swap(LinkNode* node, LinkNode* new_node);
// Return node without removing it.
LinkNode* head() { return head_; }
// Return the number of links in the list.
size_t count() const { return count_; }
private:
LinkNode* head_;
size_t count_;
};
} // namespace linker
} // namespace art
#endif // ART_COMPILER_UTILS_LINK_NODES_H_
<|endoftext|>
// Linked list implementation
// -----------------------------------------------------------------------------
template <class T>
class wxListContainerNode : public wxListContainerNodeBase<T>
{
public:
wxListContainerNode() { }
wxListContainerNode(wxListContainerNode *after,
const T& data)
: wxListContainerNodeBase<T>(after, data) { }
// Assign with reference count to allow using this class for list
wxListContainerNode& operator=(const wxListContainerNode& list)
{
wxListContainerNodeBase<T>::operator=(list);
return *this;
}
// Change the item type: this also allows changing wxListData pointer
// and any of its implementations (which also provide compare and
// reset methods)
void Assign(const wxListContainerNode& list)
{
Assign(const_cast<wxListContainerNode&>(*list.m_parent));
}
// Change the item type: this also allows changing wxListData pointer
// and any of its implementations (which also provide compare and
// reset methods)
void Assign(const T& data)
{
*static_cast<wxListContainerNode<T> *>(this) = data;
}
// Recursively assigns the list's data members to this node
// (which is a lighter version of Assign that compares contents
// of the node's list to its parent and vice versa), returning true if
// the list still contains the item, otherwise false.
bool Assign(const wxListContainerNode& list, bool recursive = false)
{
if ( !list.m_parent )
return false;
// check for current parent first
if ( list.m_parent != this )
{
// skip removing the list node itself when moving
if ( recursive )
{
list.m_parent->Unlink();
// only increase the reference count if this is the only
// reference to the item we're removing from the list
if ( list.m_parent->m_refCount == 1 )
++list.m_parent->m_refCount;
// remove this item from the list node itself
list.Unlink();
}
// remember that we're removing from the list node itself
list.m_parent->m_refCount++;
return true;
}
// also, recurse
if ( recursive )
return list.Children().Assign(this, true);
// if we're removing from the list, recurse in the parent
return list.Parent().Assign(this, true);
}
bool operator==(const wxListContainerNode& list) const
{
return this->m_parent == list.m_parent;
}
bool operator!=(const wxListContainerNode& list) const
{
return this->m_parent != list.m_parent;
}
// get the data
const T& GetItem() const
{
return *static_cast<const wxListContainerNode<T> *>(this);
}
// find the first item that is not in the list
wxListContainerNode<T> *First() const
{
for ( wxListContainerNodeBase<T> *n = m_parent;
n != NULL;
n = n->m_parent )
{
if ( !n->m_data )
return n;
}
return NULL;
}
// Find the first item that is not in the list with specified
// item type. If that data is found, the data is returned.
//
// If flags includes wxLIST_FIND_FROM_CURRENT flag, the list is searched
// starting from the current item. Otherwise, the last item found
// is returned.
wxListContainerNode<T> *Find(const wxListData& data,
int flags = wxLIST_FIND_FROM_CURRENT) const
{
wxListContainerNodeBase<T> *n = First();
if ( n == NULL || n->m_data != &data )
{
// go down the node and return the first found
n = n->m_parent;
}
while ( n != NULL && !(n->m_data->m_flags & wxLIST_FIND_
// Linked list implementation
static pa_hashmap *pa_hashmap_new(void) {
pa_hashmap *hash = pa_xnew(pa_hashmap, 1);
hash->table = pa_xnew(pa_hashmap_item, PA_HT_MAX_SIZE);
hash->size = PA_HT_MAX_SIZE;
return hash;
}
pa_hashmap* pa_hashmap_ref(pa_hashmap *m) {
pa_assert(m);
pa_assert(PA_REFCNT_VALUE(m) > 0);
pa_atomic_inc(&m->n_ref);
return m;
}
void pa_hashmap_unref(pa_hashmap *m) {
pa_assert(m);
pa_assert(PA_REFCNT_VALUE(m) > 0);
if (pa_atomic_dec_and_test(&m->n_ref))
pa_hashmap_clear(m);
}
/* The behavior of returning NULL is undefined. On success the hash table
* contains no elements and pa_hashmap_isempty() will return true. On
* failure the hash table will contain the elements of the given hash
* function and pa_hashmap_isempty() will return false. */
bool pa_hashmap_isempty(pa_hashmap *hash) {
pa_assert(hash);
return PA_REFCNT_VALUE(hash) == 0;
}
static void pa_hashmap_free(pa_hashmap *hash) {
pa_assert(hash);
while (pa_hashmap_isempty(hash))
(void) pa_atomic_inc(&hash->n_free);
pa_xfree(hash->table);
pa_xfree(hash);
}
/* Insert an item in the hash table. */
static void *pa_hashmap_add_or_steal(pa_hashmap *hash, void *n) {
void *v;
pa_assert(hash);
pa_assert(PA_REFCNT_VALUE(hash) > 0);
if (!hash->table || pa_hashmap_isempty(hash)) {
v = n;
pa_hashmap_put(hash, v, n);
return v;
}
v = pa_xrealloc(hash->table, hash->size * sizeof(hash->table[0]));
hash->table[hash->size-1] = n;
return v;
}
/* Return the first item from the hash table or NULL. */
void* pa_hashmap_get(pa_hashmap *hash, const void *key) {
void *n = NULL;
void *ret;
pa_assert(hash);
pa_assert(PA_REFCNT_VALUE(hash) > 0);
pa_assert(key);
if (hash->table && hash->size > 0) {
int i = 0;
const void *b = NULL;
while (i < hash->size && !b) {
n = hash->table[i];
b = pa_xhash(n, hash->hash_func);
i++;
}
ret = pa_xmemdup(n, hash->size);
return ret;
}
return NULL;
}
/* Put a new value into the hash table. */
void* pa_hashmap_put(pa_hashmap *hash, const void *key, const void *v) {
void *ret = NULL;
pa_assert(hash);
pa_assert(PA_REFCNT_VALUE(hash) > 0);
pa_assert(key);
pa_assert(v);
if (!hash->table || pa_hashmap_isempty(hash)) {
ret = pa_xmemdup(v, hash->size);
return ret;
}
ret = pa_xrealloc(hash->table, hash->size * sizeof(hash->table[0]));
hash->table[hash->size-1] = v;
return ret;
}
static void pa_hashmap_remove(pa_hashmap *hash, void *v) {
void *tmp;
pa_assert(hash);
pa_assert(PA_REFCNT_VALUE(hash) > 0);
/* When removing a element, we might need to remove the entire hash table
* from a single operation. This would be fine
// Linked list implementation
struct ListBase {
typedef void* Handle;
Handle next;
Handle prev;
bool isEmpty() const { return !next; }
void setNext(Handle aHandle) {
MOZ_ASSERT(!empty());
next = aHandle;
}
void setPrev(Handle aHandle) {
MOZ_ASSERT(!empty());
prev = aHandle;
}
bool remove() {
MOZ_ASSERT(!isEmpty());
Handle newHandle = next;
next = next->next;
newHandle->prev = prev;
prev->next = newHandle;
return true;
}
void prepend(Handle aHandle) {
MOZ_ASSERT(!isEmpty());
next = aHandle;
aHandle->prev = prev;
prev->next = aHandle;
}
void append(Handle aHandle) {
MOZ_ASSERT(!isEmpty());
aHandle->prev = prev;
prev->next = aHandle;
}
void removeFront() {
MOZ_ASSERT(!isEmpty());
next = next->next;
prev = next;
next->prev = prev;
}
void removeBack() {
MOZ_ASSERT(!isEmpty());
next = next->next;
prev = prev;
next->prev = next;
}
Handle first() const {
MOZ_ASSERT(!isEmpty());
return next;
}
Handle last() const {
MOZ_ASSERT(!isEmpty());
return prev;
}
Handle nextInfallible() const {
if (isEmpty()) {
return nullptr;
}
MOZ_ASSERT(!next);
return prev;
}
Handle prevInfallible() const {
if (isEmpty()) {
return nullptr;
}
MOZ_ASSERT(!prev);
return next;
}
};
template <class T>
class LinkedListElement<T, LinkedListBase> {
using ListBase = LinkedListBase;
typedef typename ListBase::Handle Handle;
ListBase::ListHeader<T> headers;
public:
using ElementType = T;
LinkedListElement() : next(nullptr) {}
MOZ_MUST_USE bool append(Handle aHandle) {
MOZ_ASSERT(!empty());
if (!next) {
next = new Handle(aHandle);
} else {
Handle last = next;
Handle nextInfallible =
firstInfallible(std::min(last->prev, last->next));
Handle nextSameInfallible =
firstSameInfallible(std::max(last->prev, last->next));
nextInfallible->next = aHandle;
if (aHandle->prev) {
aHandle->prev->next = next;
} else {
headers.setNext(nextInfallible);
}
if (last->next) {
last->next->prev = next;
} else {
headers.setPrev(nextSameInfallible);
}
}
return true;
}
MOZ_MUST_USE bool remove() {
MOZ_ASSERT(!empty());
Handle head = headers.get();
handle_type prev = nullptr;
handle_type next = head->next;
head->next = nullptr;
head->prev = nullptr;
if (next) {
Handle last = next;
handle_type lastInfallible =
firstInfallible(std::min(last->prev, last->next));
Handle lastSameInfallible =
firstSameInfallible(std::max(last->prev, last->next));
lastInfallible->next = nextInfallible;
lastSameInfallible->prev = lastInfallible;
if (last->next) {
last->next->prev = lastSameInfallible;
} else {
headers.setPrev(lastSameInfallible);
}
} else {
head->prev = prev;
}
return true;
}
void prepend(Handle aHandle) {
MOZ_ASSERT(!empty());
handle_type prev = headers.get();
Handle head = prev;
handle_type
// Linked list implementation
//#define CV_QUATERNION_LINK_FIFO_SIZE 20
namespace cv {
class QuarterGenerator {
public:
static const size_t n_limits;
QuarterGenerator();
~QuarterGenerator();
// Encodes the generated square into an array of 32 bit integers.
static void encode(const cv::Mat& input, cv::Mat& output);
// Decodes an array of 32 bit integers from an encoder's encoded byte array.
static void decode(const std::vector<uint32_t>& input, cv::Mat& output);
// Computes an In-place Montgomery representation.
static cv::Mat convert(const cv::Mat& input);
// Computes the parity of a single integer.
static uint32_t parity(uint32_t value);
// Computes the two distinct quantiles of a set of integer.
static cv::Mat quantile(cv::Mat input, uint32_t low, uint32_t high, uint32_t inverse);
private:
uint32_t eval(cv::Mat input, const std::vector<uint32_t>& offset, cv::Mat* rootr_matrix = 0);
};
} // namespace cv
#endif // CV_QUATERNION_HPP
<|endoftext|>
// Linked list implementation
typedef QLinkedList< QSharedPointer<T> > QLinkedListElement;
QT_END_NAMESPACE
QT_END_HEADER
#endif // QLINKEDLIST_H
<|endoftext|>
// Linked list implementation
template <typename T>
class linked_list
{
T *head;
T *tail;
size_t length;
public:
linked_list() : head(0), tail(0), length(0) { }
~linked_list()
{
if (head)
delete [] head;
}
T *head() const { return head; }
T *tail() const { return tail; }
void append(T *item) {
if (head) {
size_t len = head->size();
if (len >= length) {
// just shift the head
T *temp = head;
head = head->next();
head->~T();
// copy new items into the new head
if (temp)
temp->next(temp);
temp->~T();
// finally set new length
length = len;
}
}
tail->next = item;
tail = item;
length++;
}
void append(size_t n, T *item) {
// insert the list before the n items
T *p = head;
for (size_t i = 0; i < n; ++i)
p = p->next;
// insert the new items at the end of the list
p->next = item;
p->~T();
if (item)
item->next(item);
length++;
}
bool empty() const { return (head == 0); }
size_t length() const { return length; }
T &last() { return *tail; }
T *last() { return tail; }
T &front() { return *(tail - 1); }
T *begin() { return tail; }
T *end() { return tail; }
T &pop_front() {
T *n = head;
head = head->next();
if (!head)
tail = 0;
length--;
return *n;
}
T *pop_front() {
T *n = head;
head = head->next();
if (!head)
tail = 0;
length--;
return n;
}
};
template <typename T>
linked_list<T> make_linked_list(T *head)
{
linked_list<T> l(head);
return l;
}
}
#endif
<|endoftext|>
// Linked list implementation
/**
* The boost::intrusive::list class is a template specialization
* for use with the Boost.Container template parameter list class
* for storing fast sorted list elements.
*
* The template parameter T must be the type of the value_type,
* as defined below.
*
* List iterators are different from normal iterators, because
* normal iterators are infrequently used to implement the insert
* iterator and the erase_iterator and the push_front and pop_back
* algorithms, respectively. This means, that the type of the
* value_type must be T. This allows the value_type to be any
* container class that supports bidirectional iterators.
*/
template <typename T, typename List>
class list : public intrusive_list<T, intrusive_ptr_container_d::value_type> {
public:
typedef intrusive_list<T, intrusive_ptr_container_d::value_type> base;
typedef typename base::iterator iterator;
typedef typename base::const_iterator const_iterator;
typedef typename base::size_type size_type;
typedef typename base::value_type value_type;
typedef typename base::pointer pointer;
typedef typename base::const_pointer const_pointer;
typedef typename base::reference reference;
typedef typename base::const_reference const_reference;
typedef typename base::reverse_iterator reverse_iterator;
typedef typename base::const_reverse_iterator const_reverse_iterator;
typedef typename base::iterator_category iterator_category;
list()
: base()
{
}
list(const list &rhs)
: base(rhs)
{
}
list(const intrusive_ptr_container_d::value_type &rhs)
: base()
, ptr(rhs)
{
}
~list()
{
}
list &operator=(const intrusive_ptr_container_d::value_type &rhs)
{
ptr = rhs;
return *this;
}
size_type size() const
{
return ptr->size();
}
bool empty() const
{
return ptr->empty();
}
iterator begin()
{
return ptr->begin();
}
iterator end()
{
return ptr->end();
}
const_iterator begin() const
{
return ptr->begin();
}
const_iterator end() const
{
return ptr->end();
}
reverse_iterator rbegin()
{
return ptr->rbegin();
}
reverse_iterator rend()
{
return ptr->rend();
}
const_reverse_iterator rbegin() const
{
return ptr->rbegin();
}
const_reverse_iterator rend() const
{
return ptr->rend();
}
void insert(iterator position, const value_type &x)
{
ptr->insert(position, x);
}
void push_back(const value_type &x)
{
ptr->push_back(x);
}
void push_front(const value_type &x)
{
ptr->push_front(x);
}
void pop_back()
{
ptr->pop_back();
}
void pop_front()
{
ptr->pop_front();
}
void erase(iterator position)
{
ptr->erase(position);
}
void clear()
{
ptr->clear();
}
void swap(list &rhs)
{
base().swap(rhs);
std::swap(ptr, rhs.ptr);
}
private
// Linked list implementation
namespace internal {
// Convenience methods
template <typename T, typename Allocator>
class LinkedListImpl : public LinkedListNode<T> {
public:
LinkedListImpl(const T& value, size_t head, size_t size) :
LinkedListNode<T>(value, head, size) {}
};
template <typename T>
class LinkedListImpl<T, typename Allocator::template rebind<T>::other>
: public LinkedListNode<T> {
public:
LinkedListImpl(const T& value, size_t head, size_t size)
: LinkedListNode<T>(value, head, size) {}
~LinkedListImpl() {
// Following assignment form of the assignment does not
// affect the list node.
LinkedListNode<T>::~LinkedListImpl() = 0;
}
};
template <typename T, typename Allocator>
void SortedLinkedListImpl<T, Allocator>::clear() {
for (size_t i = 0; i < this->size(); ++i) {
this->get_node(i).~T();
}
this->size_ = 0;
}
template <typename T, typename Allocator>
LinkedListNode<T>* SortedLinkedListImpl<T, Allocator>::move_down(
LinkedListNode<T>* next) {
if (next == this) {
return this;
}
size_t orig_size = next->size_;
this->size_--;
if (this->size_ == 0) {
this->clear();
this->size_ = orig_size;
return next;
}
next->SetNext(this->getNext());
return next;
}
template <typename T, typename Allocator>
LinkedListNode<T>* SortedLinkedListImpl<T, Allocator>::move_up(
LinkedListNode<T>* previous) {
LinkedListNode<T>* last_move = previous;
size_t size = previous->size_;
while (size > 0) {
size_t last_size = size;
LinkedListNode<T>* first_move = last_move->GetNext();
if (first_move != this) {
first_move->SetPrev(last_move);
last_move->SetPrev(this);
size--;
} else {
last_move->SetPrev(NULL);
size = 0;
}
last_move = first_move;
}
return last_move;
}
template <typename T, typename Allocator>
void SortedLinkedListImpl<T, Allocator>::insert_front(const T& val) {
LinkedListNode<T>* n = new LinkedListNode<T>(val);
for (LinkedListNode<T>* p = this; p != NULL; p = p->GetNext()) {
p->InsertBefore(n);
}
}
template <typename T, typename Allocator>
void SortedLinkedListImpl<T, Allocator>::insert_after(const T& val) {
LinkedListNode<T>* n = new LinkedListNode<T>(val);
for (LinkedListNode<T>* p = this->GetNext(); p != NULL; p = p->GetNext()) {
p->InsertBefore(n);
}
}
template <typename T, typename Allocator>
void SortedLinkedListImpl<T, Allocator>::insert_front(
LinkedListNode<T>* node) {
InsertBefore(&*node);
}
template <typename T, typename Allocator>
void SortedLinkedListImpl<T, Allocator>::insert_after(
LinkedListNode<T>* node) {
InsertAfter(&*node);
}
template <typename T, typename Allocator>
void SortedLinkedListImpl<T, Allocator>::insert_before(
LinkedListNode<T>* node) {
InsertBefore(&node->GetNext());
}
template <typename T, typename Allocator>
LinkedListNode<T>* SortedLinkedListImpl<T, Allocator>::remove(size_t i) {
LinkedListNode<T>* p = this->get_node(i);
this->erase(p);
return p;
}
template <typename T, typename Allocator>
void SortedLinkedListImpl<T, Allocator>::reverse() {
LinkedListNode<T>* p = this->get_node(this->size() - 1);
this->insert_before(p);
}
template <typename
// Linked list implementation
class InlineTableList {
public:
InlineTableList() = default;
~InlineTableList();
// Add a new InlineTable that belongs to the list.
void Add(InlineTable* table);
// Remove the InlineTable in the list with the given key, returns the
// removed InlineTable.
InlineTable* Remove(uint32_t key);
// If the InlineTable contains a subtable, return its parent InlineTable.
InlineTable* GetParentTable(uint32_t subtable);
// For each |entry|, remove all the child entries for the given |subtable|.
// The base class implementation does not implement this method, it does not
// change any state or query it.
void RemoveSubtablesFor(uint32_t subtable);
// Reverse the order of InlineTable members.
void Reverse();
// Use this when a subtable is removed.
void RemoveEntry(uint32_t key);
// These methods are not safe to use outside the list's control loop.
size_t size() const { return list_.size(); }
void clear() { list_.clear(); }
private:
std::vector<InlineTable*> list_;
};
// InlineTableListIterator
//
// An iterator to traverse the InlineTables. It iterates on the list, returning
// the next InlineTable.
class InlineTableListIterator {
public:
InlineTableListIterator() = default;
InlineTableListIterator(InlineTableList* list) : list_(list) {}
InlineTableListIterator& operator++() {
DCHECK(list_);
++list_;
return *this;
}
InlineTable* operator*() { return &(*list_); }
private:
InlineTableList* list_;
};
// InlineTableFreeListIterator
//
// An iterator to iterate over the InlineTables without checking
// ownership or reference counting. If a given instance of InlineTableList
// cannot be iterated, the pointer will be invalid.
class InlineTableFreeListIterator {
public:
InlineTableFreeListIterator() = default;
InlineTableFreeListIterator(InlineTableList* list) : list_(list) {}
InlineTableFreeListIterator& operator++() {
DCHECK(list_);
if (!list_->parent_ || list_->owner_ != list_)
return *this;
list_ = list_->parent_->child_;
return *this;
}
InlineTable* operator*() { return &(*list_); }
private:
InlineTableList* list_;
};
// Return true if |block| is contained by |list|.
inline bool Contains(InlineTableList* list, InlineTable* block) {
return list && list->Contains(block);
}
inline bool Contains(InlineTableList* list, const InlineTable* block) {
return list && list->Contains(block);
}
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_TEXT_INLINE_TABLE_LIST_H_
<|endoftext|>
// Linked list implementation
//
template <class K> struct DLL_NODE_POOL {
DLL_NODE_POOL() : next(NULL) {}
DLL_NODE_POOL(const K& key, DLL_NODE_POOL* prev)
: next(NULL), previous(prev), key(key)
{
previous = this;
}
DLL_NODE_POOL(DLL_NODE_POOL* prev, const K& key)
: next(prev), previous(prev ? prev->previous : NULL), key(key)
{
}
DLL_NODE_POOL* previous;
DLL_NODE_POOL* next;
const K& key;
};
// The list is directly used as a stack.
template <class K> class DLL_NODE_STACK : public DLL_NODE_POOL<K> {
public:
DLL_NODE_STACK(const K& key) : DLL_NODE_POOL<K>(key)
{
}
~DLL_NODE_STACK()
{
DLL_NODE_POOL<K>::unlink_all();
}
};
// The tail of the linked list.
template <class K> class DLL_NODE_TAIL : public DLL_NODE_POOL<K> {
public:
DLL_NODE_TAIL() : DLL_NODE_POOL<K>() {}
~DLL_NODE_TAIL()
{
DLL_NODE_POOL<K>::unlink_all();
}
};
// Simple container with nodes sorted by key
template <class K, class Iterator> class DLL_NODE_CONTAINER : public DLL_NODE_STACK<K>
{
typedef DLL_NODE_STACK<K> base;
friend class DLL_NODE_STACK<K>;
friend class DLL_NODE_STACK<K>::iterator;
// "help in 'insert()'"
DLL_NODE_CONTAINER& operator=(const DLL_NODE_CONTAINER& src);
public:
DLL_NODE_CONTAINER(const K& key)
: base(key)
{
DLL_NODE_STACK<K>::insert(this);
}
DLL_NODE_CONTAINER(const K& key, DLL_NODE_CONTAINER* prev)
: base(key, prev)
{
DLL_NODE_STACK<K>::insert(this);
}
DLL_NODE_CONTAINER& operator=(const DLL_NODE_CONTAINER& src)
{
base::operator=(src);
return *this;
}
Iterator begin()
{
return base::begin();
}
Iterator end()
{
return base::end();
}
Iterator back()
{
return base::back();
}
};
template <class K> class DLL_NODE_CONTAINER_EXPORT DLL_NODE_CONTAINER_SHARED : public DLL_NODE_CONTAINER<K, std::shared_ptr<DLL_NODE_CONTAINER<K> > >
{
public:
DLL_NODE_CONTAINER_SHARED() {}
DLL_NODE_CONTAINER_SHARED(const K& key)
: DLL_NODE_CONTAINER<K, std::shared_ptr<DLL_NODE_CONTAINER<K> > >(key)
{
}
DLL_NODE_CONTAINER_SHARED(const K& key, DLL_NODE_CONTAINER* prev)
: DLL_NODE_CONTAINER<K, std::shared_ptr<DLL_NODE_CONTAINER<K> > >(key, prev)
{
}
DLL_NODE_CONTAINER_SHARED& operator=(const DLL_NODE_CONTAINER_SHARED& src)
{
return *this;
}
DLL_NODE_CONTAINER_SHARED& operator=(const DLL_NODE_CONTAINER& src)
{
return base::operator=(src);
}
};
#ifdef _MSC_VER
// Compilers do not support forward declarations
template <class K, class Iterator> DLL_NODE_CONTAINER_EXPORT DLL_NODE_CONTAINER_SHARED<K, Iterator>::DLL_NODE_CONTAINER_SHARED() {}
template <class K, class Iterator> DLL_NODE_CONTAINER_EXPORT DLL_NODE_CONTAINER_SHARED<K, Iterator>::DLL_NODE_CONTAINER_SHARED(const K& key) : base(key) {}
template <class K, class Iterator> DLL_NODE_CONTAINER_EXPORT DLL_NODE_CONTAINER_SHARED<