Commit e29bc691 authored by Max Kellermann's avatar Max Kellermann

Queue: rename internal types

parent ce57b8b6
...@@ -26,16 +26,16 @@ ...@@ -26,16 +26,16 @@
queue::queue(unsigned _max_length) queue::queue(unsigned _max_length)
:max_length(_max_length), length(0), :max_length(_max_length), length(0),
version(1), version(1),
items(g_new(struct queue_item, max_length)), items(g_new(Item, max_length)),
order((unsigned *)g_malloc(sizeof(order[0]) * max_length)), order((unsigned *)g_malloc(sizeof(order[0]) * max_length)),
id_to_position((int *)g_malloc(sizeof(id_to_position[0]) * id_to_position((int *)g_malloc(sizeof(id_to_position[0]) *
max_length * QUEUE_HASH_MULT)), max_length * HASH_MULT)),
repeat(false), repeat(false),
single(false), single(false),
consume(false), consume(false),
random(false) random(false)
{ {
for (unsigned i = 0; i < max_length * QUEUE_HASH_MULT; ++i) for (unsigned i = 0; i < max_length * HASH_MULT; ++i)
id_to_position[i] = -1; id_to_position[i] = -1;
} }
...@@ -59,7 +59,7 @@ queue::GenerateId() const ...@@ -59,7 +59,7 @@ queue::GenerateId() const
do { do {
cur++; cur++;
if (cur >= max_length * QUEUE_HASH_MULT) if (cur >= max_length * HASH_MULT)
cur = 0; cur = 0;
} while (id_to_position[cur] != -1); } while (id_to_position[cur] != -1);
...@@ -157,7 +157,7 @@ queue::SwapPositions(unsigned position1, unsigned position2) ...@@ -157,7 +157,7 @@ queue::SwapPositions(unsigned position1, unsigned position2)
void void
queue::MovePostion(unsigned from, unsigned to) queue::MovePostion(unsigned from, unsigned to)
{ {
struct queue_item item = items[from]; const Item tmp = items[from];
/* move songs to one less in from->to */ /* move songs to one less in from->to */
...@@ -171,8 +171,8 @@ queue::MovePostion(unsigned from, unsigned to) ...@@ -171,8 +171,8 @@ queue::MovePostion(unsigned from, unsigned to)
/* put song at _to_ */ /* put song at _to_ */
id_to_position[item.id] = to; id_to_position[tmp.id] = to;
items[to] = item; items[to] = tmp;
items[to].version = version; items[to].version = version;
/* now deal with order */ /* now deal with order */
...@@ -193,7 +193,7 @@ queue::MovePostion(unsigned from, unsigned to) ...@@ -193,7 +193,7 @@ queue::MovePostion(unsigned from, unsigned to)
void void
queue::MoveRange(unsigned start, unsigned end, unsigned to) queue::MoveRange(unsigned start, unsigned end, unsigned to)
{ {
struct queue_item tmp[end - start]; Item tmp[end - start];
// Copy the original block [start,end-1] // Copy the original block [start,end-1]
for (unsigned i = start; i < end; i++) for (unsigned i = start; i < end; i++)
tmp[i - start] = items[i]; tmp[i - start] = items[i];
...@@ -290,7 +290,7 @@ void ...@@ -290,7 +290,7 @@ void
queue::Clear() queue::Clear()
{ {
for (unsigned i = 0; i < length; i++) { for (unsigned i = 0; i < length; i++) {
struct queue_item *item = &items[i]; Item *item = &items[i];
assert(!song_in_database(item->song) || assert(!song_in_database(item->song) ||
song_is_detached(item->song)); song_is_detached(item->song));
...@@ -434,7 +434,7 @@ queue::FindPriorityOrder(unsigned start_order, uint8_t priority, ...@@ -434,7 +434,7 @@ queue::FindPriorityOrder(unsigned start_order, uint8_t priority,
for (unsigned i = start_order; i < length; ++i) { for (unsigned i = start_order; i < length; ++i) {
const unsigned position = OrderToPosition(i); const unsigned position = OrderToPosition(i);
const struct queue_item *item = &items[position]; const Item *item = &items[position];
if (item->priority <= priority && i != exclude_order) if (item->priority <= priority && i != exclude_order)
return i; return i;
} }
...@@ -450,7 +450,7 @@ queue::CountSamePriority(unsigned start_order, uint8_t priority) const ...@@ -450,7 +450,7 @@ queue::CountSamePriority(unsigned start_order, uint8_t priority) const
for (unsigned i = start_order; i < length; ++i) { for (unsigned i = start_order; i < length; ++i) {
const unsigned position = OrderToPosition(i); const unsigned position = OrderToPosition(i);
const struct queue_item *item = &items[position]; const Item *item = &items[position];
if (item->priority != priority) if (item->priority != priority)
return i - start_order; return i - start_order;
} }
...@@ -463,7 +463,7 @@ queue::SetPriority(unsigned position, uint8_t priority, int after_order) ...@@ -463,7 +463,7 @@ queue::SetPriority(unsigned position, uint8_t priority, int after_order)
{ {
assert(position < length); assert(position < length);
struct queue_item *item = &items[position]; Item *item = &items[position];
uint8_t old_priority = item->priority; uint8_t old_priority = item->priority;
if (old_priority == priority) if (old_priority == priority)
return false; return false;
...@@ -488,7 +488,7 @@ queue::SetPriority(unsigned position, uint8_t priority, int after_order) ...@@ -488,7 +488,7 @@ queue::SetPriority(unsigned position, uint8_t priority, int after_order)
const unsigned after_position = const unsigned after_position =
OrderToPosition(after_order); OrderToPosition(after_order);
const struct queue_item *after_item = const Item *after_item =
&items[after_position]; &items[after_position];
if (old_priority > after_item->priority || if (old_priority > after_item->priority ||
priority <= after_item->priority) priority <= after_item->priority)
......
...@@ -40,16 +40,16 @@ ...@@ -40,16 +40,16 @@
*/ */
struct queue { struct queue {
/** /**
* reserve max_length * QUEUE_HASH_MULT elements in the id * reserve max_length * HASH_MULT elements in the id
* number space * number space
*/ */
static constexpr unsigned QUEUE_HASH_MULT = 4; static constexpr unsigned HASH_MULT = 4;
/** /**
* One element of the queue: basically a song plus some queue specific * One element of the queue: basically a song plus some queue specific
* information attached. * information attached.
*/ */
struct queue_item { struct Item {
struct song *song; struct song *song;
/** the unique id of this item in the queue */ /** the unique id of this item in the queue */
...@@ -76,7 +76,7 @@ struct queue { ...@@ -76,7 +76,7 @@ struct queue {
uint32_t version; uint32_t version;
/** all songs in "position" order */ /** all songs in "position" order */
struct queue_item *items; Item *items;
/** map order numbers to positions */ /** map order numbers to positions */
unsigned *order; unsigned *order;
...@@ -148,7 +148,7 @@ struct queue { ...@@ -148,7 +148,7 @@ struct queue {
} }
int IdToPosition(unsigned id) const { int IdToPosition(unsigned id) const {
if (id >= max_length * QUEUE_HASH_MULT) if (id >= max_length * HASH_MULT)
return -1; return -1;
assert(id_to_position[id] >= -1); assert(id_to_position[id] >= -1);
...@@ -190,7 +190,7 @@ struct queue { ...@@ -190,7 +190,7 @@ struct queue {
return items[position].priority; return items[position].priority;
} }
const queue_item &GetOrderItem(unsigned i) const { const Item &GetOrderItem(unsigned i) const {
assert(IsValidOrder(i)); assert(IsValidOrder(i));
return items[OrderToPosition(i)]; return items[OrderToPosition(i)];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment