<commit_before>/*
 * Stateplex - A server-side actor model library.
 *
 * core/list.h
 *
 * (c) 2013 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Authors: <NAME>
 */

#ifndef INCLUDED_STATEPLEX_LIST_H
#define INCLUDED_STATEPLEX_LIST_H

#include <cstddef>

namespace Stateplex {

template<typename T>
class List;

template<typename T>
struct ListItem {
	ListItem<T> *mNext;
	ListItem<T> *mPrevious;

	ListItem();

	void addBetween(ListItem<T> *previous, ListItem<T> *next);
	void addBefore(ListItem<T> *existing_item);
	void addAfter(ListItem<T> *existing_item);
	void initialise();
	void remove();
	T *container();
};

template<typename T>
class List {
	ListItem<T> mItems;

public:
	List();
	
	ListItem<T> *first();
	ListItem<T> *last();
	ListItem<T> *next(ListItem<T> *item);
	ListItem<T> *previous(ListItem<T> *item);
	
	void addBetween(ListItem<T> *previous, ListItem<T> *next);
	void addHead(ListItem<T> *item);
	void addTail(ListItem<T> *item);
	void spliceHead(List<T> *list);
	void spliceTail(List<T> *list);

	bool isEmpty();
};

}

/*** Inline implementations ***/

namespace Stateplex {

template<typename T>
inline ListItem<T>::ListItem()
{
	initialise();
}

template<typename T>
inline void ListItem<T>::initialise()
{
	mNext = mPrevious = this;
}

template<typename T>
inline void ListItem<T>::addBetween(ListItem<T> *previous, ListItem<T> *next)
{
	previous->mNext = this;
	mPrevious = previous;
	mNext = next;
	next->mPrevious = this;
}

template<typename T>
inline void ListItem<T>::addBefore(ListItem<T> *existing_item)
{
	mPrevious->mNext = mNext;
	mNext->mPrevious = mPrevious;
	addBetween(existing_item->mPrevious, existing_item);
}

template<typename T>
inline void ListItem<T>::addAfter(ListItem<T> *existing_item)
{
	mNext->mPrevious = mPrevious;
	mPrevious->mNext = mNext;
	addBetween(existing_item, existing_item->mNext);
}
<commit_msg>ListItem: fixed addBefore() and addAfter()<commit_after>/*
 * Stateplex - A server-side actor model library.
 *
 * core/list.h
 *
 * (c) 2013 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Authors: <NAME>
 */

#ifndef INCLUDED_STATEPLEX_LIST_H
#define INCLUDED_STATEPLEX_LIST_H

#include <cstddef>

namespace Stateplex {

template<typename T>
class List;

template<typename T>
struct ListItem {
	ListItem<T> *mNext;
	ListItem<T> *mPrevious;

	ListItem();

	void addBetween(ListItem<T> *previous, ListItem<T> *next);
	void addBefore(ListItem<T> *existing_item);
	void addAfter(ListItem<T> *existing_item);
	void initialise();
	void remove();
	T *container();
};

template<typename T>
class List {
	ListItem<T> mItems;

public:
	List();
	
	ListItem<T> *first();
	ListItem<T> *last();
	ListItem<T> *next(ListItem<T> *item);
	ListItem<T> *previous(ListItem<T> *item);
	
	void addBetween(ListItem<T> *previous, ListItem<T> *next);
	void addHead(ListItem<T> *item);
	void addTail(ListItem<T> *item);
	void spliceHead(List<T> *list);
	void spliceTail(List<T> *list);

	bool isEmpty();
};

}

/*** Inline implementations ***/

namespace Stateplex {

template<typename T>
inline ListItem<T>::ListItem()
{
	initialise();
}

template<typename T>
inline void ListItem<T>::initialise()
{
	mNext = mPrevious = this;
}

template<typename T>
inline void ListItem<T>::addBetween(ListItem<T> *previous, ListItem<T> *next)
{
	previous->mNext = this;
	mPrevious = previous;
	mNext = next;
	next->mPrevious = this;
}

template<typename T>
inline void ListItem<T>::addBefore(ListItem<T> *existing_item)
{
	ListItem<T> *previous = existing_item->mPrevious;

	mPrevious->mNext = mNext;
	mNext->mPrevious = mPrevious;
	addBetween(previous, existing_item);
}

template<typename T>
inline void ListItem<T>::addAfter(ListItem<T> *existing_item)
{
	ListItem<T> *next = existing_item->mNext;

	mNext->mPrevious = mPrevious;
	mPrevious->mNext = mNext;
	addBetween(existing_item, next);
}

{'fraction_non_alphanumeric': 0.13223670155949582, 'fraction_numerical': 0.002563554795983764, 'mean_word_length': 5.404924760601915, 'pattern_counts': {'":': 0, '<': 87, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4294563', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1594, 'n_words': 442}