-
Notifications
You must be signed in to change notification settings - Fork 0
Tweak the SimpleSequencerImpl #23
Description
Besides the instance-specific prefix, SimpleSequencerImpl translates numbers into letters as follows:
- 0 -> a
- 1 -> b
- 25 -> z
- 26 -> ba
That's consistent, because 'a' represents zero and therefore never appears in the lead position. But it would be cooler if it did, like...
- 26 -> aa
- 51 -> az
- 52 -> ba
- 701 -> zz
- 702 -> aaa
Mathematically, the leading letter is interpreted as 1-26, while subsequent letters are interpreted as 0-25. Sounds easy, but is easy to mess up too.
The examples above interpret a single letter as 0-25, even though it's a leading letter. There is no need to encode the number 0, so this would also work:
- 1 -> a
- 26 -> z
- 27 -> aa
- 52 -> az
- 53 -> ba
The charming thing about those tweaks is that the comparator doesn't have to be changed at all. Longer identifiers correspond to higher numbers, and alphabetical sorting is correct for identifiers with the same length.