I am sorting 128-bit records in a large file (10s of GB). Algorithm works fine and currently using uint64_t
with two of these equal to one record. This is on a modern 64-bit system.
In the interest of code readability, am wondering if create a struct like typedef struct u128t {uint64_t hi, uint64_t} u128t
can be used in place of the two 64-bit records. This would make array indexing and assignment cleaner but I would have to implement a comparator function.
Is this a portable solution and should I expect this to run at the same speed as the original implementation?
Further reading:
Using struct is fine.
I would do something like this:
#if COMPILER_WHICH_SUPPORTS_128_BIT_TYPE
typedef __uint128 u128t;
#define COMPARE(a, b) ((a) == (b))
#else
typedef struct {
uint64_t hi;
uint64_t lo;
} u128t;
#define COMPARE(a, b) MyCompareFunction((a), (b))
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With