c048310c430b675d6bb84815bc8c997ead297c81
2 * mlt_deque.c -- double ended queue
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "mlt_deque.h"
24 // System header files
28 /** Private structure.
41 mlt_deque
mlt_deque_init( )
43 return calloc( 1, sizeof( struct mlt_deque_s
) );
46 /** Return the number of items in the deque.
49 int mlt_deque_count( mlt_deque
this )
54 /** Allocate space on the deque.
57 static int mlt_deque_allocate( mlt_deque
this )
59 if ( this->count
== this->size
)
61 this->list
= realloc( this->list
, sizeof( void * ) * ( this->size
+ 10 ) );
64 return this->list
== NULL
;
67 /** Push an item to the end.
70 int mlt_deque_push_back( mlt_deque
this, void *item
)
72 int error
= mlt_deque_allocate( this );
75 this->list
[ this->count
++ ] = item
;
83 void *mlt_deque_pop_back( mlt_deque
this )
85 return this->count
> 0 ?
this->list
[ -- this->count
] : NULL
;
88 /** Queue an item at the start.
91 int mlt_deque_push_front( mlt_deque
this, void *item
)
93 int error
= mlt_deque_allocate( this );
97 memmove( &this->list
[ 1 ], this->list
, ( this->count
++ ) * sizeof( void * ) );
98 this->list
[ 0 ] = item
;
104 /** Remove an item from the start.
107 void *mlt_deque_pop_front( mlt_deque
this )
111 if ( this->count
> 0 )
113 item
= this->list
[ 0 ];
114 memmove( this->list
, &this->list
[ 1 ], ( -- this->count
) * sizeof( void * ) );
120 /** Inquire on item at back of deque but don't remove.
123 void *mlt_deque_peek_back( mlt_deque
this )
125 return this->count
> 0 ?
this->list
[ this->count
- 1 ] : NULL
;
128 /** Inquire on item at front of deque but don't remove.
131 void *mlt_deque_peek_front( mlt_deque
this )
133 return this->count
> 0 ?
this->list
[ 0 ] : NULL
;
139 void mlt_deque_close( mlt_deque
this )