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 
22 #ifndef SEQ_H
23 #define SEQ_H
24 
25 #include <stdint.h>
26 #include <errno.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
35 #define SEQ_LIMIT(X) (X >> 1)
36 
40 typedef uint8_t seq8_t;
41 
45 typedef uint16_t seq16_t;
46 
50 typedef uint32_t seq32_t;
51 
55 typedef uint64_t seq64_t;
56 
69 seq8_t seq8_adds(seq8_t s, uint8_t n, uint8_t space);
70 
82 static inline seq8_t seq8_add(seq8_t s, uint8_t n)
83 {
84  return seq8_adds(s, n, UINT8_MAX);
85 }
86 
93 static inline seq8_t seq8_incs(seq8_t s, uint8_t space)
94 {
95  return seq8_adds(s, 1, space);
96 }
97 
103 static inline seq8_t seq8_inc(seq8_t s)
104 {
105  return seq8_adds(s, 1, UINT8_MAX);
106 }
107 
121 int seq8_compares(seq8_t s1, seq8_t s2, uint8_t space);
122 
135 static inline int seq8_compare(seq8_t s1, seq8_t s2)
136 {
137  return seq8_compares(s1, s2, UINT8_MAX);
138 }
139 
152 seq16_t seq16_adds(seq16_t s, uint16_t n, uint16_t space);
153 
165 static inline seq16_t seq16_add(seq16_t s, uint16_t n)
166 {
167  return seq16_adds(s, n, UINT16_MAX);
168 }
169 
176 static inline seq16_t seq16_incs(seq16_t s, uint16_t space)
177 {
178  return seq16_adds(s, 1, space);
179 }
180 
186 static inline seq16_t seq16_inc(seq16_t s)
187 {
188  return seq16_adds(s, 1, UINT16_MAX);
189 }
190 
204 int seq16_compares(seq16_t s1, seq16_t s2, uint16_t space);
205 
218 static inline int seq16_compare(seq16_t s1, seq16_t s2)
219 {
220  return seq16_compares(s1, s2, UINT16_MAX);
221 }
222 
235 seq32_t seq32_adds(seq32_t s, uint32_t n, uint32_t space);
236 
248 static inline seq32_t seq32_add(seq32_t s, uint32_t n)
249 {
250  return seq32_adds(s, n, UINT32_MAX);
251 }
252 
259 static inline seq32_t seq32_incs(seq32_t s, uint32_t space)
260 {
261  return seq32_adds(s, 1, space);
262 }
263 
269 static inline seq32_t seq32_inc(seq32_t s)
270 {
271  return seq32_adds(s, 1, UINT32_MAX);
272 }
273 
287 int seq32_compares(seq32_t s1, seq32_t s2, uint32_t space);
288 
301 static inline int seq32_compare(seq32_t s1, seq32_t s2)
302 {
303  return seq32_compares(s1, s2, UINT32_MAX);
304 }
305 
318 seq64_t seq64_adds(seq64_t s, uint64_t n, uint64_t space);
319 
331 static inline seq64_t seq64_add(seq64_t s, uint64_t n)
332 {
333  return seq64_adds(s, n, UINT64_MAX);
334 }
335 
342 static inline seq64_t seq64_incs(seq64_t s, uint64_t space)
343 {
344  return seq64_adds(s, 1, space);
345 }
346 
352 static inline seq64_t seq64_inc(seq64_t s)
353 {
354  return seq64_adds(s, 1, UINT64_MAX);
355 }
356 
370 int seq64_compares(seq64_t s1, seq64_t s2, uint64_t space);
371 
384 static inline int seq64_compare(seq64_t s1, seq64_t s2)
385 {
386  return seq64_compares(s1, s2, UINT64_MAX);
387 }
388 
389 #ifdef __cplusplus
390 }
391 #endif
392 
394 #endif /* SEQ_H */
seq16_incs
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:176
seq8_t
uint8_t seq8_t
A 8 bit sequence number.
Definition: seq.h:40
seq32_incs
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:259
seq32_adds
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.
seq16_adds
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_compare
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:384
seq16_compare
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:218
seq64_incs
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:342
seq16_add
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:165
seq8_adds
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.
seq8_add
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:82
seq64_inc
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:352
seq8_compare
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:135
seq64_t
uint64_t seq64_t
A 64 bit sequence number.
Definition: seq.h:55
seq16_t
uint16_t seq16_t
A 16 bit sequence number.
Definition: seq.h:45
seq32_compare
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:301
seq32_add
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:248
seq64_compares
int seq64_compares(seq64_t s1, seq64_t s2, uint64_t space)
Compare sequence numbers s1, s2 in the serial number space.
seq64_adds
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.
seq32_compares
int seq32_compares(seq32_t s1, seq32_t s2, uint32_t space)
Compare sequence numbers s1, s2 in the serial number space.
seq64_add
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:331
seq8_incs
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:93
seq8_inc
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:103
seq32_inc
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:269
seq16_compares
int seq16_compares(seq16_t s1, seq16_t s2, uint16_t space)
Compare sequence numbers s1, s2 in the serial number space.
seq8_compares
int seq8_compares(seq8_t s1, seq8_t s2, uint8_t space)
Compare sequence numbers s1, s2 in the serial number space.
errno.h
seq32_t
uint32_t seq32_t
A 32 bit sequence number.
Definition: seq.h:50
seq16_inc
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:186