Created
January 16, 2020 17:11
-
-
Save jonahaung/69d30da2cd23a6f690e4882739d7532b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // SwiftyTesseract.swift | |
| // Myanmar Lens | |
| // | |
| // Created by Aung Ko Min on 20/11/19. | |
| // Copyright © 2019 Aung Ko Min. All rights reserved. | |
| // | |
| struct RecognitionQueue<T: Hashable> { | |
| private var values: [T] | |
| var size: Int | |
| var allValuesMatch: Bool { | |
| guard size == values.count else { return false } | |
| return Set(values).count == 1 | |
| } | |
| init(maxElements: Int) { | |
| size = maxElements | |
| values = [T]() | |
| } | |
| mutating func enqueue(_ value: T) { | |
| values.append(value) | |
| if values.count > size { | |
| dequeue() | |
| } | |
| } | |
| @discardableResult | |
| mutating func dequeue() -> T? { | |
| if values.isEmpty { return nil } | |
| return values.remove(at: 0) | |
| } | |
| mutating func clear() { | |
| values.removeAll() | |
| } | |
| mutating func updateReliability(reliability: Accurcy) { | |
| clear() | |
| size = reliability.numberOfResults | |
| } | |
| } | |
| extension RecognitionQueue { | |
| init(reliability: Accurcy) { | |
| self.init(maxElements: reliability.numberOfResults) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment