Keep a linked list sorted
A general linked list function, llist_reorder(), is introduced that will reorder a list after a list element has changed. Some refactoring to avoid code dupliction. Background The four linked lists of appointment panel items (appointments, recurring appointments, events, recurring events) are kept sorted by inserting elements in order, either when they are first loaded from disk or when new are added. The ordering is by start time (numerical) and description (alphabetical). The user is allowed to change start time as well as description. A change is committed directly to the list item (unlike cut/paste where an item is deleted and then inserted). This may break the order. The order property is used when events are loaded from the evenlist into the day_item vector, see LLIST_FIND_FOREACH_CONT, and when looking for the next upcoming appointment, see apoint_check_next(). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
committed by
Lukas Fleischer
parent
e44613411a
commit
b44307cc83
@@ -99,8 +99,11 @@ void *llist_get_data(llist_item_t *);
|
||||
void llist_add(llist_t *, void *);
|
||||
void llist_add_sorted(llist_t *, void *, llist_fn_cmp_t);
|
||||
void llist_remove(llist_t *, llist_item_t *);
|
||||
void llist_reorder(llist_t *, void *, llist_fn_cmp_t);
|
||||
|
||||
#define LLIST_ADD(l, data) llist_add(l, data)
|
||||
#define LLIST_ADD_SORTED(l, data, fn_cmp) \
|
||||
llist_add_sorted(l, data, (llist_fn_cmp_t)fn_cmp)
|
||||
#define LLIST_REMOVE(l, i) llist_remove(l, i)
|
||||
#define LLIST_REORDER(l, data, fn_cmp) \
|
||||
llist_reorder(l, data, (llist_fn_cmp_t)fn_cmp)
|
||||
|
||||
Reference in New Issue
Block a user