Loading...
Searching...
No Matches
seq.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Cenk Gündoğan <cnkgndgn@gmail.com>
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
20
21#include <stdint.h>
22#include <errno.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
31#define SEQ_LIMIT(X) (X >> 1)
32
36typedef uint8_t seq8_t;
37
41typedef uint16_t seq16_t;
42
46typedef uint32_t seq32_t;
47
51typedef uint64_t seq64_t;
52
65seq8_t seq8_adds(seq8_t s, uint8_t n, uint8_t space);
66
78static inline seq8_t seq8_add(seq8_t s, uint8_t n)
79{
80 return seq8_adds(s, n, UINT8_MAX);
81}
82
89static inline seq8_t seq8_incs(seq8_t s, uint8_t space)
90{
91 return seq8_adds(s, 1, space);
92}
93
99static inline seq8_t seq8_inc(seq8_t s)
100{
101 return seq8_adds(s, 1, UINT8_MAX);
102}
103
117int seq8_compares(seq8_t s1, seq8_t s2, uint8_t space);
118
131static inline int seq8_compare(seq8_t s1, seq8_t s2)
132{
133 return seq8_compares(s1, s2, UINT8_MAX);
134}
135
148seq16_t seq16_adds(seq16_t s, uint16_t n, uint16_t space);
149
161static inline seq16_t seq16_add(seq16_t s, uint16_t n)
162{
163 return seq16_adds(s, n, UINT16_MAX);
164}
165
172static inline seq16_t seq16_incs(seq16_t s, uint16_t space)
173{
174 return seq16_adds(s, 1, space);
175}
176
182static inline seq16_t seq16_inc(seq16_t s)
183{
184 return seq16_adds(s, 1, UINT16_MAX);
185}
186
200int seq16_compares(seq16_t s1, seq16_t s2, uint16_t space);
201
214static inline int seq16_compare(seq16_t s1, seq16_t s2)
215{
216 return seq16_compares(s1, s2, UINT16_MAX);
217}
218
231seq32_t seq32_adds(seq32_t s, uint32_t n, uint32_t space);
232
244static inline seq32_t seq32_add(seq32_t s, uint32_t n)
245{
246 return seq32_adds(s, n, UINT32_MAX);
247}
248
255static inline seq32_t seq32_incs(seq32_t s, uint32_t space)
256{
257 return seq32_adds(s, 1, space);
258}
259
265static inline seq32_t seq32_inc(seq32_t s)
266{
267 return seq32_adds(s, 1, UINT32_MAX);
268}
269
283int seq32_compares(seq32_t s1, seq32_t s2, uint32_t space);
284
297static inline int seq32_compare(seq32_t s1, seq32_t s2)
298{
299 return seq32_compares(s1, s2, UINT32_MAX);
300}
301
314seq64_t seq64_adds(seq64_t s, uint64_t n, uint64_t space);
315
327static inline seq64_t seq64_add(seq64_t s, uint64_t n)
328{
329 return seq64_adds(s, n, UINT64_MAX);
330}
331
338static inline seq64_t seq64_incs(seq64_t s, uint64_t space)
339{
340 return seq64_adds(s, 1, space);
341}
342
348static inline seq64_t seq64_inc(seq64_t s)
349{
350 return seq64_adds(s, 1, UINT64_MAX);
351}
352
366int seq64_compares(seq64_t s1, seq64_t s2, uint64_t space);
367
380static inline int seq64_compare(seq64_t s1, seq64_t s2)
381{
382 return seq64_compares(s1, s2, UINT64_MAX);
383}
384
385#ifdef __cplusplus
386}
387#endif
388
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:380
uint16_t seq16_t
A 16 bit sequence number.
Definition seq.h:41
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:327
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:214
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:131
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:338
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:255
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:348
uint32_t seq32_t
A 32 bit sequence number.
Definition seq.h:46
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:172
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:51
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:99
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:244
uint8_t seq8_t
A 8 bit sequence number.
Definition seq.h:36
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:265
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:89
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:182
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:78
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:297
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:161