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