MCPcopy Create free account
hub / github.com/ElementsProject/elements / CompressAmount

Function CompressAmount

src/compressor.cpp:149–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147// (this is decodable, as d is in [1-9] and e is in [0-9])
148
149uint64_t CompressAmount(uint64_t n)
150{
151 if (n == 0)
152 return 0;
153 int e = 0;
154 while (((n % 10) == 0) && e < 9) {
155 n /= 10;
156 e++;
157 }
158 if (e < 9) {
159 int d = (n % 10);
160 assert(d >= 1 && d <= 9);
161 n /= 10;
162 return 1 + (n*9 + d - 1)*10 + e;
163 } else {
164 return 1 + (n - 1)*10 + 9;
165 }
166}
167
168uint64_t DecompressAmount(uint64_t x)
169{

Callers 5

SerMethod · 0.85
TestEncodeFunction · 0.85
TestDecodeFunction · 0.85
TestPairFunction · 0.85
FUZZ_TARGET_INITFunction · 0.85

Calls

no outgoing calls

Tested by 4

TestEncodeFunction · 0.68
TestDecodeFunction · 0.68
TestPairFunction · 0.68
FUZZ_TARGET_INITFunction · 0.68