rchillyard / The-repository-formerly-known-as

2 stars 12 forks source link

BigDecimal encoding #28

Closed rchillyard closed 3 years ago

rchillyard commented 4 years ago

When we HuskySort BigDecimals, it takes much longer than the system sort. There must be something wrong in the encoding, I think, even though I have unit-tested it. I'd like to know why this is so slow.

rchillyard commented 4 years ago

There was indeed something wrong in the encoding. We were converting to double and then to long. But converting to double involved writing out the BigDecimal as a String and then parting that String as a double. Whoa!

Here is the comment from Line 3275 of java.math.BigDecimal.java: // Somewhat inefficient, but guaranteed to work.

Because there are sets of BigDecimal values that may not map well to the range of longs, we also now offer a scaledBigDecimalEncoder where you tell it the power of ten by which you want to increase (or decrease with negative) the size of the BigDecimal values before converting to long.

rchillyard commented 3 years ago

This was fixed in https://github.com/rchillyard/HuskySort/commit/cf3769d60b3973d4e7d78387bc84f62a6dbbc813