This file contains 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
class LruCache<K: Hashable, V> { | |
private class Entity<V> { | |
let value: V | |
let key: K | |
var left: Entity<V>? | |
var right: Entity<V>? | |
init(value: V, key: K) { | |
self.value = value |
This file contains 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
func quicksort<T: Comparable>(_ list: [T]) -> [T] { | |
if list.count <= 1 { | |
return list | |
} | |
let pivot = list[0] | |
var smallerList = [T]() | |
var equalList = [T]() | |
var biggerList = [T]() |
This file contains 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
class Paginator { | |
struct Params { | |
let firstIndex: Int | |
} | |
let initParams: Params | |
private let pageSubject = PublishSubject<Void>() | |
This file contains 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
/// Controller for `HUD` visibility management. | |
/// Shows hud with delay to prevent interface blinking. | |
public class HudController { | |
// MARK: - Instance variables | |
private let container: UIView | |
private let delay: DispatchTimeInterval | |
private var hud: UIActivityIndicatorView? |
This file contains 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
struct CustomTableSection<HeaderItem, Item> { | |
var header: HeaderItem | |
var items: [Item] | |
} | |
struct CustomTableView<Item, Content: View, HeaderItem, HeaderContent: View>: UIViewRepresentable { | |
@Binding | |
var sections: [CustomTableSection<HeaderItem, Item>] | |
This file contains 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
import Foundation | |
public class ErrorReporter { | |
// MARK: - Aliases | |
public typealias ReportFunction = ( | |
_ error: Error, | |
_ file: StaticString, | |
_ line: UInt | |
) -> Void |
This file contains 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
/// Low-level lock that allows waiters to block efficiently on contention. | |
/// | |
/// Based on `os_unfair_lock_s` | |
public class UnfairLock { | |
// MARK: - Instance variables | |
private var unfairLock = os_unfair_lock_s() | |
// MARK: - Public |
This file contains 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
/// Property wrapper for atomic modifications | |
@propertyWrapper | |
public struct Atomic<T> { | |
private var value: T | |
private let lock = NSLock() | |
public init(wrappedValue value: T) { | |
self.value = value | |
} |
This file contains 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
public class ReadWriteLock { | |
// MARK: - Instance variables | |
private var lock = pthread_rwlock_t() | |
private var attr = pthread_rwlockattr_t() | |
// MARK: - Public | |
public init() { | |
pthread_rwlockattr_init(&attr) |
This file contains 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
/// Watcher for time measure. | |
/// | |
/// ! Non thread safe | |
public class TimeWatcher { | |
// MARK: - Static | |
public enum Interval: UInt64 { | |
case nanos = 1 | |
case mills = 1_000_000 |
OlderNewer