71 lines
989 B
C
71 lines
989 B
C
#include "internal_deque.h"
|
|
#include <stdlib.h>
|
|
|
|
i_deque_t *
|
|
i_deque_t_new
|
|
( PyObject * content
|
|
, i_deque_t * next)
|
|
{
|
|
i_deque_t * deque = malloc(sizeof(i_deque_t));
|
|
if(!deque)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
deque->content = content;
|
|
deque->next = next;
|
|
|
|
if(next)
|
|
{
|
|
deque->following = next->following + 1;
|
|
}
|
|
else
|
|
{
|
|
deque->following = 0;
|
|
}
|
|
return deque;
|
|
}
|
|
|
|
void
|
|
i_deque_t_del
|
|
(i_deque_t * deque)
|
|
{
|
|
if(deque)
|
|
{
|
|
free(deque);
|
|
}
|
|
}
|
|
|
|
PyObject *
|
|
i_deque_t_to_List
|
|
(i_deque_t * deque)
|
|
{
|
|
if(!deque)
|
|
{
|
|
return PyList_New(0);
|
|
}
|
|
PyObject * list = PyList_New(deque->following + 1);
|
|
if(!list)
|
|
{
|
|
return NULL;
|
|
}
|
|
i_deque_t * this_node;
|
|
PyObject * this_content;
|
|
|
|
size_t i;
|
|
size_t content_length = deque->following + 1;
|
|
for(i = 0; i < content_length; i++)
|
|
{
|
|
this_node = deque;
|
|
deque = deque->next;
|
|
this_content = this_node->content;
|
|
i_deque_t_del(this_node);
|
|
Py_INCREF(this_content);
|
|
|
|
PyList_SetItem(list, content_length - 1 - i, this_content);
|
|
}
|
|
return list;
|
|
|
|
}
|
|
|