Skip to content

Instantly share code, notes, and snippets.

View lamtev's full-sized avatar
🏠
Working from home

Anton Lamtev lamtev

🏠
Working from home
View GitHub Profile
@lamtev
lamtev / RandomAccessCollection+BinarySearch.swift
Created November 19, 2019 19:13
Binary search implementation that returns insertion index if element not found
import Foundation
public extension RandomAccessCollection {
func binarySearch(startIndex: Index? = nil, endIndex: Index? = nil, comparator: (Element) -> Int) -> (index: Index, found: Bool) {
var low = startIndex ?? self.startIndex
var high = index(before: endIndex ?? self.endIndex)
while low <= high {
let mid = index(low, offsetBy: distance(from: low, to: high) >> 1)
let midVal = self[mid]
@lamtev
lamtev / 100Users.json
Created February 22, 2020 22:36
JSON examples on which ZippyJSON is slower than Apple
[{"firstName":"Evelina","lastName":"Schoen","email":"vicente.larkin@example.com","login":"Stew Ng","passwordHash":"w!^n@R!4@B#*&4inIF**@O#Ao","gender":"MALE","avatarUrl":"https://s3.amazonaws.com/uifaces/faces/twitter/amandabuzard/128.jpg","country":"Cambodia","city":"Bratislava","zipCode":589927,"phone":"504-641-1740 x3218","isVip":false,"isFamous":false},{"firstName":"Verlie","lastName":"Becker","email":"patria.torphy@example.com","login":"Eve O'Lution","passwordHash":"HxO^fy7lemCj2*jy2whp0Y","gender":"MALE","avatarUrl":"https://s3.amazonaws.com/uifaces/faces/twitter/ernestsemerda/128.jpg","country":"Brunei Darussalam","city":"Buenos Aires","zipCode":181276,"phone":"(906) 860-8891 x4304","isVip":false,"isFamous":false},{"firstName":"Murray","lastName":"Greenholt","email":"charla.daniel@example.com","login":"Brice Tagg","passwordHash":"8M0ho&@4d5UIMt32*C4$sN67","gender":"FEMALE","avatarUrl":"https://s3.amazonaws.com/uifaces/faces/twitter/kvasnic/128.jpg","country":"Monaco","city":"Monrovia","zipCode":82148,"