aboutsummaryrefslogtreecommitdiff
path: root/ringbuff.c
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2020-10-04 14:36:07 +0200
committerThomas Schmucker <ts@its1.de>2020-10-04 14:36:07 +0200
commit6fb072f62c2f50118dd5cb377d10c76ece51e5fb (patch)
treed4572ba16b2ab45a7601b70cdb5811023ac3b390 /ringbuff.c
parentace33ff2c18c732e7ac30c49d95f7c35e06d7cee (diff)
downloaddata-structures-6fb072f62c2f50118dd5cb377d10c76ece51e5fb.tar.gz
data-structures-6fb072f62c2f50118dd5cb377d10c76ece51e5fb.tar.bz2
data-structures-6fb072f62c2f50118dd5cb377d10c76ece51e5fb.zip
Setze srcut-Marker...
Diffstat (limited to 'ringbuff.c')
-rw-r--r--ringbuff.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/ringbuff.c b/ringbuff.c
index a963beb..c800f62 100644
--- a/ringbuff.c
+++ b/ringbuff.c
@@ -5,19 +5,24 @@
5 5
6#include "util.h" 6#include "util.h"
7 7
8/* --8<-- ring_type */
8typedef int T; 9typedef int T;
9 10
10struct ring_buffer { 11struct ring_buffer {
11 size_t head, tail; 12 size_t head, tail;
12 T array[8]; /* fit for your needs... */ 13 T array[8]; /* fit for your needs... */
13}; 14};
15/* -->8-- */
14 16
17/* --8<-- ring_init */
15void 18void
16ring_init(struct ring_buffer *rb) 19ring_init(struct ring_buffer *rb)
17{ 20{
18 rb->head = rb->tail = 0; 21 rb->head = rb->tail = 0;
19} 22}
23/* -->8-- */
20 24
25/* --8<-- ring_push_front */
21bool 26bool
22ring_push_front(struct ring_buffer *rb, T data) 27ring_push_front(struct ring_buffer *rb, T data)
23{ 28{
@@ -31,7 +36,9 @@ ring_push_front(struct ring_buffer *rb, T data)
31 36
32 return true; 37 return true;
33} 38}
39/* -->8-- */
34 40
41/* --8<-- ring_push_back */
35bool 42bool
36ring_push_back(struct ring_buffer *rb, T data) 43ring_push_back(struct ring_buffer *rb, T data)
37{ 44{
@@ -45,7 +52,9 @@ ring_push_back(struct ring_buffer *rb, T data)
45 52
46 return true; 53 return true;
47} 54}
55/* -->8-- */
48 56
57/* --8<-- ring_pop_front */
49bool 58bool
50ring_pop_front(struct ring_buffer *rb, T *data) 59ring_pop_front(struct ring_buffer *rb, T *data)
51{ 60{
@@ -59,7 +68,9 @@ ring_pop_front(struct ring_buffer *rb, T *data)
59 68
60 return true; 69 return true;
61} 70}
71/* -->8-- */
62 72
73/* --8<-- ring_pop_back */
63bool 74bool
64ring_pop_back(struct ring_buffer *rb, T *data) 75ring_pop_back(struct ring_buffer *rb, T *data)
65{ 76{
@@ -73,18 +84,23 @@ ring_pop_back(struct ring_buffer *rb, T *data)
73 84
74 return true; 85 return true;
75} 86}
87/* -->8-- */
76 88
89/* --8<-- ring_put */
77bool 90bool
78ring_put(struct ring_buffer *rb, T data) 91ring_put(struct ring_buffer *rb, T data)
79{ 92{
80 return ring_push_back(rb, data); 93 return ring_push_back(rb, data);
81} 94}
95/* -->8-- */
82 96
97/* --8<-- ring_get */
83bool 98bool
84ring_get(struct ring_buffer *rb, T *data) 99ring_get(struct ring_buffer *rb, T *data)
85{ 100{
86 return ring_pop_front(rb, data); 101 return ring_pop_front(rb, data);
87} 102}
103/* -->8-- */
88 104
89void 105void
90f() 106f()