| 147 | // (this is decodable, as d is in [1-9] and e is in [0-9]) |
| 148 | |
| 149 | uint64_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 | |
| 168 | uint64_t DecompressAmount(uint64_t x) |
| 169 | { |
no outgoing calls