VLink  2.0.0
A high-performance communication middleware
uint128.h 文件参考

Portable 128-bit unsigned integer with native-fastpath multiplication. 更多...

#include <cstdint>
#include <iostream>
#include <type_traits>
#include <utility>
#include "./macros.h"
uint128.h 的引用(Include)关系图:

浏览源代码.

class  vlink::Uint128
 128-bit unsigned integer represented as two 64-bit halves with full operator support. 更多...
 
struct  std::hash< vlink::Uint128 >
 std::hash specialisation enabling vlink::Uint128 keys in unordered containers. 更多...
 

命名空间

 

类型定义

using vlink::uint128_t = Uint128
 Convenience alias matching the lowercase fixed-width style of the standard integer types. 更多...
 

详细描述

Portable 128-bit unsigned integer with native-fastpath multiplication.

vlink::Uint128 stores the value as a pair of uint64_t halves (high_, low_). On GCC and Clang 64-bit targets the multiplication, division and modulo paths delegate to the compiler-native __uint128_t for maximum performance; on platforms without that builtin the portable fallback (mul_u128_fallback / u128_divmod) is used.

Supported operator set:

Category Operators Notes
Arithmetic + - * / % += -= *= /= %= Division throws on divisor 0
Bitwise OR AND XOR NOT shift compound-assign Shifts clamp to [0, 128]
Comparison == != < > <= >= Lexicographic over (high, low)
Increment ++ – (prefix and postfix) Carry/borrow crosses the 64-bit line
Stream operator<<(std::ostream&) Uppercase hexadecimal output
Implicit construction from integral types
The single-argument constructor is intentionally non-explicit so integral literals can flow into Uint128 transparently. Signed source values are sign-extended, unsigned values are zero-extended, and __uint128_t source values are split into halves.
Conversion back to __uint128_t
An explicit operator __uint128_t() is provided on platforms that expose the type.
std::hash specialisation
A std::hash<vlink::Uint128> specialisation at the bottom of this file enables use inside std::unordered_map and std::unordered_set.
Example
vlink::Uint128 a(0, UINT64_MAX);
assert(c == b);
std::unordered_map<vlink::uint128_t, std::string> map;
map[vlink::Uint128(0xDEAD, 0xBEEF)] = "key";