Skip to content

Commit

Permalink
Moved multiple declarations of "extension UnsignedInteger{}" into one…
Browse files Browse the repository at this point in the history
… declaration
  • Loading branch information
Dennis-Cherchenko committed Nov 29, 2016
1 parent 5a2cba9 commit ce47ba7
Showing 1 changed file with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@

import Foundation

extension UnsignedInteger {
public static func ip_random() -> Self {
let intMax = Int(ip_maxValue.toIntMax())
let rand = random(inRange: 0...intMax)
return self.init(ip_safely: rand)
}
}

// TODO: evaluate whether we should move random to be a member of CountableClosedRange
public func random(inRange range: CountableClosedRange<Int>) -> Int {
let diff = range.upperBound - range.lowerBound
Expand All @@ -26,6 +18,12 @@ public func random(inRange range: CountableClosedRange<Int>) -> Int {

// TODO: write tests for this extension
extension UnsignedInteger {
public static func ip_random() -> Self {
let intMax = Int(ip_maxValue.toIntMax())
let rand = random(inRange: 0...intMax)
return self.init(ip_safely: rand)
}

public init(ip_data: NSData) {
let hexInt = ip_data.ip_hexInt ?? 0
self.init(ip_safely: hexInt)
Expand Down Expand Up @@ -69,18 +67,15 @@ extension UnsignedInteger {
public func ip_containsMask(_ mask: Self) -> Bool {
return (self & mask) == mask
}
}

// TODO: write tests for this extension
extension UnsignedInteger {

public static var ip_maxValue: Self {
return ip_bitStackOfLength(ip_maximumNumberOfBits)
}

public static var ip_maximumNumberOfBits: Int {
return MemoryLayout<Self>.size * 8
}

// TODO: needs documentation - what is this bitstack stuff?
public static func ip_bitStackOfLength(_ length: Int) -> Self {
let maxLength = ip_maximumNumberOfBits
Expand All @@ -94,10 +89,7 @@ extension UnsignedInteger {
}
return stack
}
}

// TODO: write tests for this extension
extension UnsignedInteger {

public init<T : SignedInteger>(ip_safely value: T) {
if value < 0 {
self.init(ip_safely: UInt8(0))
Expand Down

0 comments on commit ce47ba7

Please sign in to comment.