#ifndef SIMPLICITY_BOUNDED_H
#define SIMPLICITY_BOUNDED_H
#include <stdbool.h>
#include <stdint.h>
typedef uint_least32_t ubounded;
#define UBOUNDED_MAX UINT32_MAX
static inline ubounded bounded_max(ubounded x, ubounded y) {
return x <= y ? y : x;
}
static inline ubounded bounded_add(ubounded x, ubounded y) {
return UBOUNDED_MAX < x ? UBOUNDED_MAX
: UBOUNDED_MAX - x < y ? UBOUNDED_MAX
: x + y;
}
static inline void bounded_inc(ubounded* x) {
if (*x < UBOUNDED_MAX) (*x)++;
}
static inline ubounded pad(bool right, ubounded a, ubounded b) {
return bounded_max(a, b) - (right ? b : a);
}
enum { overhead = 100 };
#endif