clist
A multi-mode C linked list library/implementation
Loading...
Searching...
No Matches
clist.h
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 * Copyright (c) 2022 Zhengli Wang
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"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * 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 THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
39#include <stdlib.h>
40
41#ifndef __CLIST_H
42#define __CLIST_H
47struct node
48{
73 struct node *prev;
74 void *item;
75 struct node *next;
76};
77
78struct clist
79{
112 struct node *begin;
113 struct node *current;
114 struct node *end;
115 size_t item_size;
116 unsigned long current_index;
118};
119
134struct clist *clist_init(size_t item_size);
135
147size_t clist_free(struct clist *clist);
148
167void *clist_append(struct clist *clist, const void *item);
168
182void *clist_pop(struct clist *clist);
183
194size_t clist_length(const struct clist *clist);
195
210void *clist_jump(struct clist *clist, unsigned long index);
211
222void *clist_read(const struct clist *clist);
223
237void *clist_write(const struct clist *clist, void *item);
238
256void *clist_insert(struct clist *clist, void *item, unsigned long index);
257
273void *clist_remove(struct clist *clist, unsigned long index);
274
279#endif
void * clist_insert(struct clist *clist, void *item, unsigned long index)
Insert an item.
size_t clist_free(struct clist *clist)
Frees a list.
Definition: clist.c:51
size_t clist_length(const struct clist *clist)
Returns the length of the list.
void * clist_pop(struct clist *clist)
Pops the last item from a clist.
Definition: clist.c:94
void * clist_append(struct clist *clist, const void *item)
Append an item.
Definition: clist.c:76
struct clist * clist_init(size_t item_size)
Create a clist.
Definition: clist.c:35
void * clist_remove(struct clist *clist, unsigned long index)
Remove an item.
void * clist_jump(struct clist *clist, unsigned long index)
Jump to the given index.
void * clist_write(const struct clist *clist, void *item)
Replace the item on the current index.
void * clist_read(const struct clist *clist)
Return the item on the current index.
A double-way linked list.
Definition: clist.h:79
unsigned long current_index
Definition: clist.h:116
struct node * begin
Definition: clist.h:112
size_t item_size
Definition: clist.h:115
struct node * current
Definition: clist.h:113
struct node * end
Definition: clist.h:114
size_t list_length
Definition: clist.h:117
A single node element for the list.
Definition: clist.h:48
void * item
Definition: clist.h:74
struct node * prev
Definition: clist.h:73
struct node * next
Definition: clist.h:75