@@ -7,14 +7,6 @@
8import Foundation
8import Foundation
10−func getRandomNum(_ min: Int, _ max: Int) -> Int {
12− return Int(random() % max) + min
14− return Int(arc4random_uniform(UInt32(max)) + UInt32(min))
18struct SafeDict<Key: Hashable, Value> {
10struct SafeDict<Key: Hashable, Value> {
19 private var queue = DispatchQueue(label: "soy.iko.safeDict.queue", attributes: .concurrent)
11 private var queue = DispatchQueue(label: "soy.iko.safeDict.queue", attributes: .concurrent)
@@ -41,9 +33,9 @@ struct SafeDict<Key: Hashable, Value> {
41 mutating func removeRandom() -> Key? {
33 mutating func removeRandom() -> Key? {
42 var key: Key?
34 var key: Key?
43 queue.sync(flags: .barrier) {
35 queue.sync(flags: .barrier) {
44− if dict.count > 0 {
36+ key = dict.keys.randomElement()
45− key = Array(dict.keys)[getRandomNum(0, dict.count)]
37+ if let key = key {
46− dict[key!] = nil
38+ dict[key] = nil
49 return key
41 return key