tumblr/collins — pull request #181 by byxorna (2014-07-18 03:01:06+00:00)
Title: Gabe fix ipallocation

@maddalab @Primer42 This is an attempt to fix fix broken IP allocation in ranges larger than a /24 when the last address in a /24 is consumed (and incorrectly identified as a local maxima).

This makes sure that the localMax address in the set of consumed addresses (what we increment to get the next address) does not have a neighbor to its right while crossing octet boundaries properly, and does not land on the last address of the range.

Testable with:
```
import util._

val calc = IpAddressCalc(2886737920L,4294963200L, Some("172.16.32.100") )

def gabefunc(calc: IpAddressCalc, sortedAddresses: List[Long]): Option[Long] = {
val minAddress = calc.minAddressAsLong
val maxAddress = calc.maxAddressAsLong
lazy val localMaximaAddresses = for {
i <- Range(0, sortedAddresses.size-1).inclusive.toStream
curr = sortedAddresses(i)
next = sortedAddresses.lift(i+1)
nextAddress = calc.incrementAddressUnchecked(curr)
if (next.map{_ > nextAddress}.getOrElse(true))
if (curr < calc.maxAddressAsLong)
} yield curr

localMaximaAddresses.headOption
}

gabefunc(calc, List(2886741130L,2886741131L,2886741134L)) //Some(.139) 2886741131L
gabefunc(calc, List(2886742010L,2886742011L,2886742012L,2886742013L)) //Some(.253) 2886742013L
gabefunc(calc, List(2886742010L,2886742011L,2886742012L,2886742013L,2886742014L)) //None, .47.254 range is used to end (start at front)
gabefunc(calc, List(2886738173L,2886738174L)) //172.16.32.254 is used, should return 2886738174L (.254 to increment to .1)
gabefunc(calc, List(2886738173L,2886738174L,2886738177L)) //172.16.32.254, 33.1 is used, Should return 2886738177L (.33.1)
gabefunc(calc, List(2886738173L,2886738174L,2886738178L)) //172.16.32.254, 33.2 is used, Should return 2886738174L to increment to 33.1

```