4 ms·
Seems much more complicated than just changing the comparator to compare lengths first.
by gefh 9y ago
Seems much more complicated than just changing the comparator to compare lengths first.
- neunhoef 9y agoThat is right, if you have access to your comparator, then this is much easier. However, it would still not work well for negative numbers, and, in many cases you sit client side and do not have access to your database engine.
- cousin_it 9y agoIt's easy to extend the comparator to negative numbers, just check for the minus sign as well.
- vesinisa 9y agoWhich would additionally preserve trivial human-readability of the stored numbers - one of the reasons of choosing JSON in the first place.
- simias 9y agoThis scheme is still human readable, you just have to skip the length prefix and you get a simple number after that. It's not really human-writeable however... Although if you wanted to save space you could also store the number itself in a bigger base to reduce the number of "digits".
- kwillets 9y agoThat's fine until you get numbers with decimal points.
- Terr_ 9y agoOr some system puts in leading zeroes.
- kevin_thibedeau 9y agoBetter yet, implement a sort that handles numeric substrings: https://nedbatchelder.com/blog/200712/human_sorting.html https://nedbatchelder.com/blog/200712/human_sorting.html