On Monday, December 01, 2003 11:24 AM, Fergal Daly wrote:
>> Taking an interval as input, this module will construct the
>> smallest set of prefixes, such that all numbers in the interval
>> will match exactly one of the prefixes, and no prefix will match
>> a number not in the interval.
>
> You need to say something about the length of the number because as it
> 3000-3999 produces just 3 and there are a lot of numbers that start
> with 3 but which aren't in the interval.
I understand you angle. But this all stems from trying to generate a routing
table for a telephony switch. In telephony switches, the dialled number is
analysed starting from the first (left-most) digit, and the routing decision
is made as soon as possible (this will often be *before* the final digit has
been dialled[1]). So, if there is a routing entry '3456', then number
'34567' would be routed in the same way as '3456789'.
I totally agree that when generating prefixes from number intervals, this
depends squarely on the involved numbers being the same number of digits.
But telephone numbers *will* be the same length in the same prefix-area[2].
And when using this algorithm for handling of IP-adresses, the numbers are
also always the same length.
Obviously, if the numbers are of variable length, then we have a different
situation, that cannot easily be handled this way. Maybe I should check $lo
and $hi to ensure they are the same length...
> 2900-3999 into a single regex string which will match if and only
> if the number is in any of the intervals
>
> ^(?:29\d{2}|3\d{3})$
Intersting proposistion. Assuming that $lo and $hi are the same length, then
doing
$n = length($lo)-length($_);
$p .= $n ? "\d{$n}" : '';
to each prefix should do the trick. I'll be adding that to the module.
Thanks for the feedback!
/Lars
[1] This will not be the case for mobile phones, which use 'en-bloc'
signalling ('all-digits-at-once') instead of the described 'overlap'
signalling ('one-digit-at-a-time'). The routing descision will be made in
the same way, though.
[2] Since this is the only way the telephony switch can know when the number
you are dialling is 'complete'.