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