core/queue: Add a queue_has() function
Used to check if a track is on a queue. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
afb2653f65
commit
9ec2497ac5
11
core/queue.c
11
core/queue.c
|
@ -220,6 +220,17 @@ void queue_clear(struct queue *queue)
|
||||||
__queue_clear(queue, n);
|
__queue_clear(queue, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool queue_has(struct queue *queue, struct track *track)
|
||||||
|
{
|
||||||
|
struct queue_iter it;
|
||||||
|
|
||||||
|
queue_for_each(queue, &it) {
|
||||||
|
if (queue_iter_val(&it) == track)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void queue_updated(struct queue *queue, struct track *track)
|
void queue_updated(struct queue *queue, struct track *track)
|
||||||
{
|
{
|
||||||
struct queue_iter it;
|
struct queue_iter it;
|
||||||
|
|
|
@ -161,6 +161,9 @@ 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 *);
|
||||||
|
|
||||||
|
/* Called to check if a queue has a track. */
|
||||||
|
bool queue_has(struct queue *, struct track *);
|
||||||
|
|
||||||
/* Called to tell the queue that a track has been updated. */
|
/* Called to tell the queue that a track has been updated. */
|
||||||
void queue_updated(struct queue *, struct track *);
|
void queue_updated(struct queue *, struct track *);
|
||||||
|
|
||||||
|
|
|
@ -238,13 +238,18 @@ static void test_stress(unsigned int N)
|
||||||
g_assert_cmpuint(i, ==, N);
|
g_assert_cmpuint(i, ==, N);
|
||||||
g_assert_cmpuint(queue_size(&q), ==, ex_size);
|
g_assert_cmpuint(queue_size(&q), ==, ex_size);
|
||||||
|
|
||||||
/* queue_remove_all() */
|
/* queue_remove_all() and queue_has() */
|
||||||
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);
|
||||||
|
if (N > 0)
|
||||||
|
test_equal(queue_has(&q, track), (bool)true);
|
||||||
|
else
|
||||||
|
test_equal(queue_has(&q, track), (bool)false);
|
||||||
test_equal(queue_remove_all(&q, track), N / 13);
|
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);
|
||||||
|
test_equal(queue_has(&q, track), (bool)false);
|
||||||
|
|
||||||
/* queue_erase() = false */
|
/* queue_erase() = false */
|
||||||
can_erase = false;
|
can_erase = false;
|
||||||
|
|
Loading…
Reference in New Issue