2015-05-05 19:51:38 +00:00
|
|
|
/**
|
|
|
|
@file list.c
|
|
|
|
@brief ENet linked list functions
|
|
|
|
*/
|
|
|
|
#define ENET_BUILDING_LIB 1
|
|
|
|
#include "enet/enet.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
@defgroup list ENet linked list utility functions
|
|
|
|
@ingroup private
|
|
|
|
@{
|
|
|
|
*/
|
2018-09-23 21:17:31 +00:00
|
|
|
void enet_list_clear(ENetList* list)
|
2015-05-05 19:51:38 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
list->sentinel.next = &list->sentinel;
|
|
|
|
list->sentinel.previous = &list->sentinel;
|
2015-05-05 19:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ENetListIterator
|
2018-09-23 21:17:31 +00:00
|
|
|
enet_list_insert(ENetListIterator position, void* data)
|
2015-05-05 19:51:38 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
ENetListIterator result = (ENetListIterator)data;
|
2015-05-05 19:51:38 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
result->previous = position->previous;
|
|
|
|
result->next = position;
|
2015-05-05 19:51:38 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
result->previous->next = result;
|
|
|
|
position->previous = result;
|
2015-05-05 19:51:38 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
return result;
|
2015-05-05 19:51:38 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void* enet_list_remove(ENetListIterator position)
|
2015-05-05 19:51:38 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
position->previous->next = position->next;
|
|
|
|
position->next->previous = position->previous;
|
2015-05-05 19:51:38 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
return position;
|
2015-05-05 19:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ENetListIterator
|
2018-09-23 21:17:31 +00:00
|
|
|
enet_list_move(ENetListIterator position, void* dataFirst, void* dataLast)
|
2015-05-05 19:51:38 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
ENetListIterator first = (ENetListIterator)dataFirst,
|
|
|
|
last = (ENetListIterator)dataLast;
|
2015-05-05 19:51:38 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
first->previous->next = last->next;
|
|
|
|
last->next->previous = first->previous;
|
2015-05-05 19:51:38 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
first->previous = position->previous;
|
|
|
|
last->next = position;
|
2015-05-05 19:51:38 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
first->previous->next = first;
|
|
|
|
position->previous = last;
|
|
|
|
|
|
|
|
return first;
|
2015-05-05 19:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2018-09-23 21:17:31 +00:00
|
|
|
enet_list_size(ENetList* list)
|
2015-05-05 19:51:38 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
size_t size = 0;
|
|
|
|
ENetListIterator position;
|
|
|
|
|
|
|
|
for (position = enet_list_begin(list);
|
|
|
|
position != enet_list_end(list);
|
|
|
|
position = enet_list_next(position))
|
|
|
|
++size;
|
|
|
|
|
|
|
|
return size;
|
2015-05-05 19:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @} */
|