lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Pete Kay wrote:
> [snip] 
> For regex, I think it assumes a certain number of digits for each part. 
> If the number of digits is variable but is contained in a "set", is it
> possible to do it efficiently in lua?

So, one way is sequential:
(1) '3' -> miss
(2) '35' -> miss
(3) '350' -> hit

Or:
(a) grab 3 digits
(b) '307' -> hit, table returns '30'

In (b), '300' to '309' will be mapped to '30'. The lookup table
will need to be dynamically generated from raw data. But it's one
lookup only. It's kinda like how zlib does Huffman decoding. '7'
for RU/KZ may be dealt with separately.

For both cases, it is probably necessary to deal with '1'
separately, because the next 3 digits will be the area code, which
can then be optionally validated with a second table lookup.

Grabbing and looking up 4 digits at one go will need thousands of
entries in the lookup table but folds in the 1-XXX validation
logic... Or grab the first 2 digits and use a 2-level tree with
two lookups needed...

-- 
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia