@@ -40,11 +40,8 @@ public struct Entropy {
40
40
static let bitsPerByte : UInt8 = 8
41
41
private static let log2_10 : Float = log2 ( 10 )
42
42
43
- public enum Tmp : UInt {
44
- case one = 1 , two, three, four
45
- }
46
-
47
43
/// Powers of ten
44
+ @available ( * , deprecated, message: " Use 1.0eNN " )
48
45
public enum Power : UInt {
49
46
case ten01 = 1 ,
50
47
ten02, ten03, ten04, ten05, ten06, ten07, ten08, ten09, ten10, ten11,
@@ -65,7 +62,9 @@ public struct Entropy {
65
62
///
66
63
/// - return: Bits of entropy required to cover the *risk* of repeat in *total* items.
67
64
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
69
68
}
70
69
71
70
/// Calculates required bits of entropy
@@ -74,6 +73,7 @@ public struct Entropy {
74
73
/// - parameter risk: Accepted probability expressed as 1 in *10^risk* chance of repeat
75
74
///
76
75
/// - return: Bits of entropy required to cover the *risk* of repeat in *total* items.
76
+ @available ( * , deprecated, message: " Use bits:(Float,Float) " )
77
77
public static func bits( for numStrings: Float , risk: Power ) -> Float {
78
78
let log2Risk = Float ( risk. rawValue) * log2_10
79
79
return total ( numStrings: numStrings, log2Risk: log2Risk)
@@ -85,6 +85,7 @@ public struct Entropy {
85
85
/// - parameter risk: Accepted probability expressed as 1 in *risk* chance of repeat
86
86
///
87
87
/// - return: Bits of entropy required to cover the *risk* of repeat in *total* items.
88
+ @available ( * , deprecated, message: " Use bits:(Float,Float) " )
88
89
public static func bits( for numStrings: Power , risk: Power ) -> Float {
89
90
if numStrings < . ten05 {
90
91
return bits ( for: powf ( 10 , Float ( numStrings. rawValue) ) , risk: risk)
@@ -94,6 +95,7 @@ public struct Entropy {
94
95
}
95
96
}
96
97
98
+ // CxTBD Remove with deprecated methods
97
99
private static func total( numStrings: Float , log2Risk: Float ) -> Float {
98
100
guard 0 < numStrings else { return 0 }
99
101
let N = numStrings < 10001 ? log2 ( Float ( numStrings) ) + log2( Float ( numStrings- 1 ) ) : 2 * log2( Float ( numStrings) )
0 commit comments