core/queue: queue_remove_all() returns count of tracks removed
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
378ff72307
commit
afb2653f65
13
core/queue.c
13
core/queue.c
|
@ -192,17 +192,24 @@ void queue_remove(struct queue *queue, unsigned int index)
|
||||||
__queue_remove(queue, &it);
|
__queue_remove(queue, &it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void queue_remove_all(struct queue *queue, struct track *track)
|
unsigned int queue_remove_all(struct queue *queue, struct track *track)
|
||||||
{
|
{
|
||||||
|
unsigned int count = 0;
|
||||||
struct queue_iter it;
|
struct queue_iter it;
|
||||||
|
|
||||||
while (queue_at(queue, 0) == track)
|
while (queue_at(queue, 0) == track) {
|
||||||
queue_remove(queue, 0);
|
queue_remove(queue, 0);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
queue_for_each(queue, &it) {
|
queue_for_each(queue, &it) {
|
||||||
if (queue_iter_val(&it) == track)
|
if (queue_iter_val(&it) == track) {
|
||||||
__queue_remove(queue, &it);
|
__queue_remove(queue, &it);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void queue_clear(struct queue *queue)
|
void queue_clear(struct queue *queue)
|
||||||
|
|
|
@ -156,7 +156,7 @@ void queue_erase(struct queue *, unsigned int);
|
||||||
void queue_remove(struct queue *, unsigned int);
|
void queue_remove(struct queue *, unsigned int);
|
||||||
|
|
||||||
/* Called to remove all instances of the track from the queue. */
|
/* Called to remove all instances of the track from the queue. */
|
||||||
void queue_remove_all(struct queue *, struct track *);
|
unsigned int queue_remove_all(struct queue *, struct track *);
|
||||||
|
|
||||||
/* Called to remove all tracks from the queue. */
|
/* Called to remove all tracks from the queue. */
|
||||||
void queue_clear(struct queue *);
|
void queue_clear(struct queue *);
|
||||||
|
|
|
@ -242,7 +242,7 @@ static void test_stress(unsigned int N)
|
||||||
track = track_get(0);
|
track = track_get(0);
|
||||||
ex_length -= track->tr_length * (N / 13);
|
ex_length -= track->tr_length * (N / 13);
|
||||||
ex_size -= (N / 13);
|
ex_size -= (N / 13);
|
||||||
queue_remove_all(&q, track);
|
test_equal(queue_remove_all(&q, track), N / 13);
|
||||||
test_equal(q.q_length, ex_length);
|
test_equal(q.q_length, ex_length);
|
||||||
test_equal(queue_size(&q), ex_size);
|
test_equal(queue_size(&q), ex_size);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue