seq.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Cenk Gündoğan <cnkgndgn@gmail.com>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
24 #ifndef SEQ_H
25 #define SEQ_H
26 
27 #include <stdint.h>
28 #include <errno.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
37 #define SEQ_LIMIT(X) (X >> 1)
38 
42 typedef uint8_t seq8_t;
43 
47 typedef uint16_t seq16_t;
48 
52 typedef uint32_t seq32_t;
53 
57 typedef uint64_t seq64_t;
58 
71 seq8_t seq8_adds(seq8_t s, uint8_t n, uint8_t space);
72 
84 static inline seq8_t seq8_add(seq8_t s, uint8_t n)
85 {
86  return seq8_adds(s, n, UINT8_MAX);
87 }
88 
95 static inline seq8_t seq8_incs(seq8_t s, uint8_t space)
96 {
97  return seq8_adds(s, 1, space);
98 }
99 
105 static inline seq8_t seq8_inc(seq8_t s)
106 {
107  return seq8_adds(s, 1, UINT8_MAX);
108 }
109 
123 int seq8_compares(seq8_t s1, seq8_t s2, uint8_t space);
124 
137 static inline int seq8_compare(seq8_t s1, seq8_t s2)
138 {
139  return seq8_compares(s1, s2, UINT8_MAX);
140 }
141 
154 seq16_t seq16_adds(seq16_t s, uint16_t n, uint16_t space);
155 
167 static inline seq16_t seq16_add(seq16_t s, uint16_t n)
168 {
169  return seq16_adds(s, n, UINT16_MAX);
170 }
171 
178 static inline seq16_t seq16_incs(seq16_t s, uint16_t space)
179 {
180  return seq16_adds(s, 1, space);
181 }
182 
188 static inline seq16_t seq16_inc(seq16_t s)
189 {
190  return seq16_adds(s, 1, UINT16_MAX);
191 }
192 
206 int seq16_compares(seq16_t s1, seq16_t s2, uint16_t space);
207 
220 static inline int seq16_compare(seq16_t s1, seq16_t s2)
221 {
222  return seq16_compares(s1, s2, UINT16_MAX);
223 }
224 
237 seq32_t seq32_adds(seq32_t s, uint32_t n, uint32_t space);
238 
250 static inline seq32_t seq32_add(seq32_t s, uint32_t n)
251 {
252  return seq32_adds(s, n, UINT32_MAX);
253 }
254 
261 static inline seq32_t seq32_incs(seq32_t s, uint32_t space)
262 {
263  return seq32_adds(s, 1, space);
264 }
265 
271 static inline seq32_t seq32_inc(seq32_t s)
272 {
273  return seq32_adds(s, 1, UINT32_MAX);
274 }
275 
289 int seq32_compares(seq32_t s1, seq32_t s2, uint32_t space);
290 
303 static inline int seq32_compare(seq32_t s1, seq32_t s2)
304 {
305  return seq32_compares(s1, s2, UINT32_MAX);
306 }
307 
320 seq64_t seq64_adds(seq64_t s, uint64_t n, uint64_t space);
321 
333 static inline seq64_t seq64_add(seq64_t s, uint64_t n)
334 {
335  return seq64_adds(s, n, UINT64_MAX);
336 }
337 
344 static inline seq64_t seq64_incs(seq64_t s, uint64_t space)
345 {
346  return seq64_adds(s, 1, space);
347 }
348 
354 static inline seq64_t seq64_inc(seq64_t s)
355 {
356  return seq64_adds(s, 1, UINT64_MAX);
357 }
358 
372 int seq64_compares(seq64_t s1, seq64_t s2, uint64_t space);
373 
386 static inline int seq64_compare(seq64_t s1, seq64_t s2)
387 {
388  return seq64_compares(s1, s2, UINT64_MAX);
389 }
390 
391 #ifdef __cplusplus
392 }
393 #endif
394 
396 #endif /* SEQ_H */
static seq16_t seq16_incs(seq16_t s, uint16_t space)
Increment a sequence number s by 1 in the serial number space.
Definition: seq.h:178
uint16_t seq16_t
A 16 bit sequence number.
Definition: seq.h:47
static int seq32_compare(seq32_t s1, seq32_t s2)
Compare sequence numbers s1, s2 in the serial number space UINT32_MAX.
Definition: seq.h:303
static seq64_t seq64_add(seq64_t s, uint64_t n)
Addition of a 64 bit sequence number s and a positive integer n in the serial number space UINT64_MAX...
Definition: seq.h:333
int seq16_compares(seq16_t s1, seq16_t s2, uint16_t space)
Compare sequence numbers s1, s2 in the serial number space.
int seq32_compares(seq32_t s1, seq32_t s2, uint32_t space)
Compare sequence numbers s1, s2 in the serial number space.
int seq64_compares(seq64_t s1, seq64_t s2, uint64_t space)
Compare sequence numbers s1, s2 in the serial number space.
seq8_t seq8_adds(seq8_t s, uint8_t n, uint8_t space)
Addition of a 8 bit sequence number s and a positive integer n in the serial number space...
static int seq64_compare(seq64_t s1, seq64_t s2)
Compare sequence numbers s1, s2 in the serial number space UINT64_MAX.
Definition: seq.h:386
seq32_t seq32_adds(seq32_t s, uint32_t n, uint32_t space)
Addition of a 32 bit sequence number s and a positive integer n in the serial number space...
static seq32_t seq32_inc(seq32_t s)
Increment a sequence number s by 1 in the serial number space UINT32_MAX.
Definition: seq.h:271
static seq16_t seq16_add(seq16_t s, uint16_t n)
Addition of a 16 bit sequence number s and a positive integer n in the serial number space UINT16_MAX...
Definition: seq.h:167
static seq8_t seq8_inc(seq8_t s)
Increment a sequence number s by 1 in the serial number space UINT8_MAX.
Definition: seq.h:105
static int seq16_compare(seq16_t s1, seq16_t s2)
Compare sequence numbers s1, s2 in the serial number space UINT16_MAX.
Definition: seq.h:220
static seq64_t seq64_incs(seq64_t s, uint64_t space)
Increment a sequence number s by 1 in the serial number space.
Definition: seq.h:344
static seq8_t seq8_incs(seq8_t s, uint8_t space)
Increment a sequence number s by 1 in the serial number space.
Definition: seq.h:95
seq16_t seq16_adds(seq16_t s, uint16_t n, uint16_t space)
Addition of a 16 bit sequence number s and a positive integer n in the serial number space...
seq64_t seq64_adds(seq64_t s, uint64_t n, uint64_t space)
Addition of a 64 bit sequence number s and a positive integer n in the serial number space...
static seq64_t seq64_inc(seq64_t s)
Increment a sequence number s by 1 in the serial number space UINT64_MAX.
Definition: seq.h:354
static seq32_t seq32_incs(seq32_t s, uint32_t space)
Increment a sequence number s by 1 in the serial number space.
Definition: seq.h:261
static int seq8_compare(seq8_t s1, seq8_t s2)
Compare sequence numbers s1, s2 in the serial number space UINT8_MAX.
Definition: seq.h:137
static seq32_t seq32_add(seq32_t s, uint32_t n)
Addition of a 32 bit sequence number s and a positive integer n in the serial number space UINT32_MAX...
Definition: seq.h:250
static seq8_t seq8_add(seq8_t s, uint8_t n)
Addition of a 8 bit sequence number s and a positive integer n in the serial number space UINT8_MAX...
Definition: seq.h:84
uint32_t seq32_t
A 32 bit sequence number.
Definition: seq.h:52
uint8_t seq8_t
A 8 bit sequence number.
Definition: seq.h:42
static seq16_t seq16_inc(seq16_t s)
Increment a sequence number s by 1 in the serial number space UINT16_MAX.
Definition: seq.h:188
int seq8_compares(seq8_t s1, seq8_t s2, uint8_t space)
Compare sequence numbers s1, s2 in the serial number space.
uint64_t seq64_t
A 64 bit sequence number.
Definition: seq.h:57