Numerically largest entry in a trie of digits
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Apr 20 00:12:30 UTC 2022
On Tue, Apr 19, 2022 at 02:37:07PM -0700, Ali Çehreli via Digitalmars-d wrote:
> On 4/19/22 14:28, H. S. Teoh wrote:
> > On Tue, Apr 19, 2022 at 09:16:18PM +0000, Dom DiSc via Digitalmars-d
> wrote:
>
> >> Is it necessary to store decimal numbers?
> >> Because if they would be stored binary, the highest number would
> >> automatically be among the longest strings.
> >
> > Obviously, the same holds for decimal numbers.
>
> I think Dom DiSc meant zero pad all numbers to have the same maximum
> length? If there is indeed a maximum length that does not incur too
> much cost (I think tries naturally don't have that kind of cost?),
> then the rightmost will be the highest number. (?)
[...]
!!! Ali, you're a genius! Pad the numbers with 0's up to some maximum
number of digits (for this particular trie I'm not expecting more than a
handful of digits anyway), and that would ensure numerical order ==
lexicographic order, so the problem becomes trivial. It also
simultaneously solves a bunch of other issues I have, all stemming from
the fact that with digit strings of non-equal lengths, numerical order
!= lexicographic order.
Thanks!!!
T
--
Why have vacation when you can work?? -- EC
More information about the Digitalmars-d
mailing list