On Wed, Jun 18, 2014 at 12:18 PM, Eric Rubin-Smith <eas....@gmail.com>
wrote:

> Carlos Ferreira wrote:
>
> > 1 - There a data type named IPV6 Address.  2 - there is a table where
> > this data type must be in.  ( can be a set of fields, one blob, one
> string
> > ...)
> >
> > You want to:
> >
> > Given a certain IPV6, find in the database the existent IPV6 record with
> > the longest equal prefix to the given IPV6 value.
>
> Not quite.  Perhaps you were confused by my (probably unclear) use of
> the word "prefix".
>
> The data structure contains a set of IPv6 *network prefixes*.  A prefix
> is the first N bits of an IPv6 address and is denoted as an IP address
> with a suffix of (128-N) bits of zeros, along with the length of the
> prefix:
>
> feed:beef::/32
>
> (here N==32).
>
> An IPv6 address is inside this prefix iff its first 32 bits are equal to
> feed:beef.


The phrase you're looking for here is "CIDR block". The way I'd handle this
is something like this:

Expand the prefix into the full feed:beef:0000:etc

Insert into a table (start binary(16), mask_length int)

select top 1 binary,length from table where start <= @input order by binary
desc

Check if the row is inside the range returned. This will take a single
index seek.

-- 
Cory Nelson
http://int64.org
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to