Skip to content

Instantly share code, notes, and snippets.

@jonahaung
Created January 16, 2020 17:11
Show Gist options
  • Select an option

  • Save jonahaung/69d30da2cd23a6f690e4882739d7532b to your computer and use it in GitHub Desktop.

Select an option

Save jonahaung/69d30da2cd23a6f690e4882739d7532b to your computer and use it in GitHub Desktop.
//
// 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