janvanbesien / java-ipv6

Java library to represent IPv6 addresses, networks, and related concepts
Apache License 2.0
85 stars 33 forks source link

Please add an efficient IPv6AddressRange.size() #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Please add an efficient size method to the IPv6AddressRange class?
The current inefficient workaround is to iterate the range and count.
Thanks. 

Original issue reported on code.google.com by Moshe.El...@gmail.com on 29 Jun 2013 at 8:56

GoogleCodeExporter commented 9 years ago
Good idea, I'll look into it.

Original comment by janvanbesien@gmail.com on 30 Jun 2013 at 12:50

GoogleCodeExporter commented 9 years ago
size() method added.

Note that you can use the implementation (using BigInteger) as inspiration for 
a more efficient workaround in your code while awaiting a new release of the 
java-ipv6 library.

    public BigInteger size()
    {
        BigInteger firstAsBigInteger = new BigInteger(1, first.toByteArray());
        BigInteger lastAsBigInteger = new BigInteger(1, last.toByteArray());

        // note that first and last are included in the range.
        return lastAsBigInteger.subtract(firstAsBigInteger).add(BigInteger.ONE);
    }

Original comment by janvanbesien@gmail.com on 30 Jun 2013 at 1:18

GoogleCodeExporter commented 9 years ago
Great! Thanks!

Original comment by Moshe.El...@gmail.com on 30 Jun 2013 at 2:00

GoogleCodeExporter commented 9 years ago

Original comment by janvanbesien@gmail.com on 8 Jul 2013 at 12:53

GoogleCodeExporter commented 9 years ago

Original comment by janvanbesien@gmail.com on 23 Jul 2013 at 9:18