@@ -40,11 +40,8 @@ public struct Entropy {
4040 static let bitsPerByte : UInt8 = 8
4141 private static let log2_10 : Float = log2 ( 10 )
4242
43- public enum Tmp : UInt {
44- case one = 1 , two, three, four
45- }
46-
4743 /// Powers of ten
44+ @available ( * , deprecated, message: " Use 1.0eNN " )
4845 public enum Power : UInt {
4946 case ten01 = 1 ,
5047 ten02, ten03, ten04, ten05, ten06, ten07, ten08, ten09, ten10, ten11,
@@ -65,7 +62,9 @@ public struct Entropy {
6562 ///
6663 /// - return: Bits of entropy required to cover the *risk* of repeat in *total* items.
6764 public static func bits( for numStrings: Float , risk: Float ) -> Float {
68- return total ( numStrings: numStrings, log2Risk: log2 ( risk) )
65+ guard 0 < numStrings else { return 0 }
66+ let N = numStrings < 10001 ? log2 ( numStrings) + log2( numStrings- 1 ) : 2 * log2( numStrings)
67+ return N + log2( risk) - 1
6968 }
7069
7170 /// Calculates required bits of entropy
@@ -74,6 +73,7 @@ public struct Entropy {
7473 /// - parameter risk: Accepted probability expressed as 1 in *10^risk* chance of repeat
7574 ///
7675 /// - return: Bits of entropy required to cover the *risk* of repeat in *total* items.
76+ @available ( * , deprecated, message: " Use bits:(Float,Float) " )
7777 public static func bits( for numStrings: Float , risk: Power ) -> Float {
7878 let log2Risk = Float ( risk. rawValue) * log2_10
7979 return total ( numStrings: numStrings, log2Risk: log2Risk)
@@ -85,6 +85,7 @@ public struct Entropy {
8585 /// - parameter risk: Accepted probability expressed as 1 in *risk* chance of repeat
8686 ///
8787 /// - return: Bits of entropy required to cover the *risk* of repeat in *total* items.
88+ @available ( * , deprecated, message: " Use bits:(Float,Float) " )
8889 public static func bits( for numStrings: Power , risk: Power ) -> Float {
8990 if numStrings < . ten05 {
9091 return bits ( for: powf ( 10 , Float ( numStrings. rawValue) ) , risk: risk)
@@ -94,6 +95,7 @@ public struct Entropy {
9495 }
9596 }
9697
98+ // CxTBD Remove with deprecated methods
9799 private static func total( numStrings: Float , log2Risk: Float ) -> Float {
98100 guard 0 < numStrings else { return 0 }
99101 let N = numStrings < 10001 ? log2 ( Float ( numStrings) ) + log2( Float ( numStrings- 1 ) ) : 2 * log2( Float ( numStrings) )
0 commit comments