From aa9ffcd04d3100627a147f015919976681627627 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 23 Jan 2009 00:06:38 +0100 Subject: queue: merged songs, songMod, positionToId into struct queue_item Move everything which belongs together into one common struct. This simplifies the implementation of several queue operations. --- src/queue.h | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src/queue.h') diff --git a/src/queue.h b/src/queue.h index 098424cdd..e27a470d9 100644 --- a/src/queue.h +++ b/src/queue.h @@ -33,6 +33,20 @@ enum { QUEUE_HASH_MULT = 4, }; +/** + * One element of the queue: basically a song plus some queue specific + * information attached. + */ +struct queue_item { + struct song *song; + + /** the unique id of this item in the queue */ + unsigned id; + + /** when was this item last changed? */ + uint32_t version; +}; + /** * A queue of songs. This is the backend of the playlist: it contains * an ordered list of songs. @@ -54,17 +68,11 @@ struct queue { uint32_t version; /** all songs in "position" order */ - struct song **songs; - - /** holds version a song was modified on */ - uint32_t *songMod; + struct queue_item *items; /** map order numbers to positions */ unsigned *order; - /** map positions to song ids */ - unsigned *positionToId; - /** map song ids to posiitons */ int *idToPosition; @@ -142,7 +150,7 @@ queue_position_to_id(const struct queue *queue, unsigned position) { assert(position < queue->length); - return queue->positionToId[position]; + return queue->items[position].id; } static inline unsigned @@ -174,7 +182,7 @@ queue_get(const struct queue *queue, unsigned position) { assert(position < queue->length); - return queue->songs[position]; + return queue->items[position].song; } /** @@ -197,8 +205,8 @@ queue_song_newer(const struct queue *queue, unsigned position, assert(position < queue->length); return version > queue->version || - queue->songMod[position] >= version || - queue->songMod[position] == 0; + queue->items[position].version >= version || + queue->items[position].version == 0; } /** -- cgit v1.2.3