core/queue: Add a function to resort the queue
This can be combined with the Q_ADD_FRONT flag for efficient bulk insertions. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
0b84b6180c
commit
9701da5392
|
@ -153,6 +153,7 @@ void collection :: init(struct queue_ops *ops)
|
|||
if (TRACK(track)->tr_library->li_enabled)
|
||||
queue_add(&library_q, TRACK(track));
|
||||
}
|
||||
queue_unset_flag(&library_q, Q_ADD_FRONT);
|
||||
|
||||
library_q.load();
|
||||
if (!library_q.q_sort) {
|
||||
|
@ -161,7 +162,6 @@ void collection :: init(struct queue_ops *ops)
|
|||
queue_sort(&library_q, COMPARE_TRACK, false);
|
||||
}
|
||||
|
||||
queue_unset_flag(&library_q, Q_ADD_FRONT);
|
||||
queue_set_flag(&library_q, Q_SAVE_SORT);
|
||||
queue_set_flag(&library_q, Q_SAVE_FLAGS);
|
||||
}
|
||||
|
@ -222,6 +222,7 @@ void collection :: set_enabled(struct library *library, bool enabled)
|
|||
return;
|
||||
|
||||
library_set_enabled(library, enabled);
|
||||
queue_set_flag(&library_q, Q_ADD_FRONT);
|
||||
|
||||
db_for_each(dbe, next, track_db_get()) {
|
||||
track = TRACK(dbe);
|
||||
|
@ -232,6 +233,9 @@ void collection :: set_enabled(struct library *library, bool enabled)
|
|||
queue_remove_all(&library_q, track);
|
||||
}
|
||||
}
|
||||
|
||||
queue_unset_flag(&library_q, Q_ADD_FRONT);
|
||||
queue_resort(&library_q);
|
||||
}
|
||||
|
||||
queue *collection :: get_queue()
|
||||
|
|
|
@ -19,8 +19,13 @@ public:
|
|||
struct set_iter it;
|
||||
|
||||
clear();
|
||||
queue_set_flag(this, Q_ADD_FRONT);
|
||||
|
||||
set_for_each(&ent->ie_set, &it)
|
||||
queue_add(this, track_get(it.it_val));
|
||||
|
||||
queue_unset_flag(this, Q_ADD_FRONT);
|
||||
queue_resort(this);
|
||||
}
|
||||
|
||||
unsigned int find_average_count()
|
||||
|
@ -57,8 +62,13 @@ public:
|
|||
avg = find_average_count();
|
||||
|
||||
clear();
|
||||
queue_set_flag(this, Q_ADD_FRONT);
|
||||
|
||||
db_for_each(track, next, track_db_get())
|
||||
dynamic_add(name, TRACK(track), avg);
|
||||
|
||||
queue_unset_flag(this, Q_ADD_FRONT);
|
||||
queue_resort(this);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
13
core/queue.c
13
core/queue.c
|
@ -174,6 +174,14 @@ struct track *queue_next(struct queue *queue)
|
|||
return __queue_selected(queue);
|
||||
}
|
||||
|
||||
void queue_resort(struct queue *queue)
|
||||
{
|
||||
_q_sort(&queue->q_tracks, track_less_than, queue->q_sort);
|
||||
|
||||
for (unsigned int i = 0; i < queue_size(queue); i++)
|
||||
__queue_updated(queue, i);
|
||||
}
|
||||
|
||||
void queue_sort(struct queue *queue, enum compare_t sort, bool reset)
|
||||
{
|
||||
GSList *cur = NULL;
|
||||
|
@ -199,9 +207,6 @@ void queue_sort(struct queue *queue, enum compare_t sort, bool reset)
|
|||
queue->q_sort = g_slist_append(queue->q_sort, GINT_TO_POINTER(sort));
|
||||
|
||||
out_sort:
|
||||
_q_sort(&queue->q_tracks, track_less_than, queue->q_sort);
|
||||
|
||||
for (unsigned int i = 0; i < queue_size(queue); i++)
|
||||
__queue_updated(queue, i);
|
||||
queue_resort(queue);
|
||||
__queue_save(queue, Q_SAVE_SORT);
|
||||
}
|
||||
|
|
|
@ -100,7 +100,10 @@ void queue_selected(struct queue *, unsigned int);
|
|||
/* Called to pick the next track from the queue. */
|
||||
struct track *queue_next(struct queue *);
|
||||
|
||||
/* Called to sort the queue. */
|
||||
/* Called to sort the queue without changing sort order. */
|
||||
void queue_resort(struct queue *);
|
||||
|
||||
/* Called to change the sort order and resort the queue. */
|
||||
void queue_sort(struct queue *, enum compare_t, bool);
|
||||
|
||||
#endif /* OCARINA_CORE_QUEUE_H */
|
||||
|
|
Loading…
Reference in New Issue