A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 146 lines 4.0 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2014 by Michael Sevakis 11 * 12 * This program is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; either version 2 15 * of the License, or (at your option) any later version. 16 * 17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 * KIND, either express or implied. 19 * 20 ****************************************************************************/ 21#ifndef LINKED_LIST_H 22#define LINKED_LIST_H 23 24#include <stddef.h> 25 26/*** 27 ** NOTES: 28 ** Node field order chosen so that one type can alias the other for forward 29 ** list traveral by the same code. 30 ** 31 ** Structures are separate, even if logically equivalent, to perform compile- 32 ** time type checking. 33 ** 34 */ 35 36 37/* (L)inked (L)ist 38 * 39 * Format: 40 * 41 * XX->YY->ZZ->0 42 * head--^ ^ 43 * tail----------+ 44 */ 45struct ll_head 46{ 47 struct ll_node *head; /* First list item */ 48 struct ll_node *tail; /* Last list item (to make insert_last O(1)) */ 49}; 50 51struct ll_node 52{ 53 struct ll_node *next; /* Next list item */ 54}; 55 56/** 57 * Initializes the singly-linked list 58 */ 59static inline void ll_init(struct ll_head *list) 60{ 61 list->head = NULL; 62 list->tail = NULL; 63} 64 65void ll_insert_next(struct ll_head *list, struct ll_node *node, 66 struct ll_node *newnode); 67void ll_insert_last(struct ll_head *list, struct ll_node *node); 68void ll_remove_next(struct ll_head *list, struct ll_node *node); 69void ll_remove(struct ll_head *list, struct ll_node *node); 70void ll_insert_first(struct ll_head *list, struct ll_node *node); 71void ll_remove_first(struct ll_head *list); 72 73 74/* (L)inked (L)ist (D)double 75 * 76 * Format: 77 * 78 * 0<-XX<->YY<->ZZ->0 79 * head----^ ^ 80 * tail--------------+ 81 */ 82struct lld_head 83{ 84 struct lld_node *head; /* First list item */ 85 struct lld_node *tail; /* Last list item (to make insert_last O(1)) */ 86}; 87 88struct lld_node 89{ 90 struct lld_node *next; /* Next list item */ 91 struct lld_node *prev; /* Previous list item */ 92}; 93 94/** 95 * Initializes the doubly-linked list 96 */ 97static inline void lld_init(struct lld_head *list) 98{ 99 list->head = NULL; 100 list->tail = NULL; 101 102 /* tail could be stored in first item's prev pointer but this simplifies 103 the routines and maintains the non-circularity */ 104} 105 106void lld_insert_next(struct lld_head *list, struct lld_node *node, 107 struct lld_node *newnode); 108void lld_insert_prev(struct lld_head *list, struct lld_node *node, 109 struct lld_node *newnode); 110void lld_insert_first(struct lld_head *list, struct lld_node *node); 111void lld_insert_last(struct lld_head *list, struct lld_node *node); 112void lld_remove(struct lld_head *list, struct lld_node *node); 113 114 115/* (L)inked (L)ist (D)ouble (C)ircular 116 * 117 * Format: 118 * +----------------+ 119 * | | 120 * +->XX<->YY<->ZZ<-+ 121 * head------^ 122 */ 123struct lldc_head 124{ 125 struct lldc_node *head; /* First list item */ 126}; 127 128struct lldc_node 129{ 130 struct lldc_node *next; /* Next list item */ 131 struct lldc_node *prev; /* Previous list item */ 132}; 133 134/** 135 * Initializes the doubly-linked circular list 136 */ 137static inline void lldc_init(struct lldc_head *list) 138{ 139 list->head = NULL; 140} 141 142void lldc_insert_first(struct lldc_head *list, struct lldc_node *node); 143void lldc_insert_last(struct lldc_head *list, struct lldc_node *node); 144void lldc_remove(struct lldc_head *list, struct lldc_node *node); 145 146#endif /* LINKED_LIST_H */