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 
9 #pragma once
10 
24 #include <stdint.h>
25 #include <errno.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
34 #define SEQ_LIMIT(X) (X >> 1)
35 
39 typedef uint8_t seq8_t;
40 
44 typedef uint16_t seq16_t;
45 
49 typedef uint32_t seq32_t;
50 
54 typedef uint64_t seq64_t;
55 
68 seq8_t seq8_adds(seq8_t s, uint8_t n, uint8_t space);
69 
81 static inline seq8_t seq8_add(seq8_t s, uint8_t n)
82 {
83  return seq8_adds(s, n, UINT8_MAX);
84 }
85 
92 static inline seq8_t seq8_incs(seq8_t s, uint8_t space)
93 {
94  return seq8_adds(s, 1, space);
95 }
96 
102 static inline seq8_t seq8_inc(seq8_t s)
103 {
104  return seq8_adds(s, 1, UINT8_MAX);
105 }
106 
120 int seq8_compares(seq8_t s1, seq8_t s2, uint8_t space);
121 
134 static inline int seq8_compare(seq8_t s1, seq8_t s2)
135 {
136  return seq8_compares(s1, s2, UINT8_MAX);
137 }
138 
151 seq16_t seq16_adds(seq16_t s, uint16_t n, uint16_t space);
152 
164 static inline seq16_t seq16_add(seq16_t s, uint16_t n)
165 {
166  return seq16_adds(s, n, UINT16_MAX);
167 }
168 
175 static inline seq16_t seq16_incs(seq16_t s, uint16_t space)
176 {
177  return seq16_adds(s, 1, space);
178 }
179 
185 static inline seq16_t seq16_inc(seq16_t s)
186 {
187  return seq16_adds(s, 1, UINT16_MAX);
188 }
189 
203 int seq16_compares(seq16_t s1, seq16_t s2, uint16_t space);
204 
217 static inline int seq16_compare(seq16_t s1, seq16_t s2)
218 {
219  return seq16_compares(s1, s2, UINT16_MAX);
220 }
221 
234 seq32_t seq32_adds(seq32_t s, uint32_t n, uint32_t space);
235 
247 static inline seq32_t seq32_add(seq32_t s, uint32_t n)
248 {
249  return seq32_adds(s, n, UINT32_MAX);
250 }
251 
258 static inline seq32_t seq32_incs(seq32_t s, uint32_t space)
259 {
260  return seq32_adds(s, 1, space);
261 }
262 
268 static inline seq32_t seq32_inc(seq32_t s)
269 {
270  return seq32_adds(s, 1, UINT32_MAX);
271 }
272 
286 int seq32_compares(seq32_t s1, seq32_t s2, uint32_t space);
287 
300 static inline int seq32_compare(seq32_t s1, seq32_t s2)
301 {
302  return seq32_compares(s1, s2, UINT32_MAX);
303 }
304 
317 seq64_t seq64_adds(seq64_t s, uint64_t n, uint64_t space);
318 
330 static inline seq64_t seq64_add(seq64_t s, uint64_t n)
331 {
332  return seq64_adds(s, n, UINT64_MAX);
333 }
334 
341 static inline seq64_t seq64_incs(seq64_t s, uint64_t space)
342 {
343  return seq64_adds(s, 1, space);
344 }
345 
351 static inline seq64_t seq64_inc(seq64_t s)
352 {
353  return seq64_adds(s, 1, UINT64_MAX);
354 }
355 
369 int seq64_compares(seq64_t s1, seq64_t s2, uint64_t space);
370 
383 static inline int seq64_compare(seq64_t s1, seq64_t s2)
384 {
385  return seq64_compares(s1, s2, UINT64_MAX);
386 }
387 
388 #ifdef __cplusplus
389 }
390 #endif
391 
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:383
uint16_t seq16_t
A 16 bit sequence number.
Definition: seq.h:44
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:330
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 seq16_compare(seq16_t s1, seq16_t s2)
Compare sequence numbers s1, s2 in the serial number space UINT16_MAX.
Definition: seq.h:217
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:134
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:341
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:258
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:351
uint32_t seq32_t
A 32 bit sequence number.
Definition: seq.h:49
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.
int seq8_compares(seq8_t s1, seq8_t s2, uint8_t space)
Compare sequence numbers s1, s2 in the serial number space.
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.
int seq64_compares(seq64_t s1, seq64_t s2, uint64_t space)
Compare sequence numbers s1, s2 in the serial number space.
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:175
int seq16_compares(seq16_t s1, seq16_t s2, uint16_t space)
Compare sequence numbers s1, s2 in the serial number space.
uint64_t seq64_t
A 64 bit sequence number.
Definition: seq.h:54
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:102
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:247
uint8_t seq8_t
A 8 bit sequence number.
Definition: seq.h:39
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:268
int seq32_compares(seq32_t s1, seq32_t s2, uint32_t space)
Compare sequence numbers s1, s2 in the serial number space.
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:92
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 seq16_t seq16_inc(seq16_t s)
Increment a sequence number s by 1 in the serial number space UINT16_MAX.
Definition: seq.h:185
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:81
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:300
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:164