1 /*
2 
3   Copyright (c) 2015 Martin Sustrik
4 
5   Permission is hereby granted, free of charge, to any person obtaining a copy
6   of this software and associated documentation files (the "Software"),
7   to deal in the Software without restriction, including without limitation
8   the rights to use, copy, modify, merge, publish, distribute, sublicense,
9   and/or sell copies of the Software, and to permit persons to whom
10   the Software is furnished to do so, subject to the following conditions:
11 
12   The above copyright notice and this permission notice shall be included
13   in all copies or substantial portions of the Software.
14 
15   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21   IN THE SOFTWARE.
22 
23 */
24 
25 #include <stddef.h>
26 
27 #include "slist.h"
28 
mill_slist_init(struct mill_slist * self)29 void mill_slist_init(struct mill_slist *self) {
30     self->first = NULL;
31     self->last = NULL;
32 }
33 
mill_slist_push(struct mill_slist * self,struct mill_slist_item * item)34 void mill_slist_push(struct mill_slist *self, struct mill_slist_item *item) {
35     item->next = self->first;
36     self->first = item;
37     if(!self->last)
38         self->last = item;
39 }
40 
mill_slist_push_back(struct mill_slist * self,struct mill_slist_item * item)41 void mill_slist_push_back(struct mill_slist *self,
42       struct mill_slist_item *item) {
43     item->next = NULL;
44     if(!self->last)
45         self->first = item;
46     else
47         self->last->next = item;
48     self->last = item;
49 }
50 
mill_slist_pop(struct mill_slist * self)51 struct mill_slist_item *mill_slist_pop(struct mill_slist *self) {
52     if(!self->first)
53         return NULL;
54     struct mill_slist_item *it = self->first;
55     self->first = self->first->next;
56     if(!self->first)
57         self->last = NULL;
58     return it;
59 }
60 
61