I hereby claim:
- I am guanshanliu on github.
- I am guanshanliu (https://keybase.io/guanshanliu) on keybase.
- I have a public key whose fingerprint is 4D2A 8562 7939 E41E 6A32 EFE8 D823 7440 5617 4DC7
To claim this, I am signing this object:
extension Heap { | |
static func sort(_ elements: [Element], sort: @escaping (Element, Element) -> Bool) -> [Element] { | |
var heap = Heap(sort: sort) | |
for e in elements { | |
heap.insert(e) | |
} | |
var result = [Element]() | |
while !heap.isEmpty { | |
result.append(heap.remove()!) | |
} |
/// Complexity: O(log n) | |
public mutating func remove() -> Element? { | |
guard !isEmpty else { return nil } | |
elements.swapAt(0, count - 1) | |
defer { | |
shiftDown(from: 0) | |
} | |
return elements.removeLast() | |
} |
/// Complexity: O(log n) | |
public mutating func insert(_ element: Element) { | |
elements.append(element) | |
shiftUp(from: count - 1) | |
} | |
private mutating func shiftUp(from index: Int) { | |
var child = index | |
var parent = parentIndex(forChildAt: child) | |
while child > 0 && sort(elements[child], elements[parent]) { |
public var isEmpty: Bool { | |
return elements.isEmpty | |
} | |
public var count: Int { | |
return elements.count | |
} | |
public func leftChildIndex(forParentAt index: Int) -> Int { | |
return 2 * index + 1 |
public struct Heap<Element: Equatable> { | |
private var elements = [Element]() | |
private let sort: (Element, Element) -> Bool | |
public init(sort: @escaping (Element, Element) -> Bool) { | |
self.sort = sort | |
} | |
} |
import Cocoa | |
//typealias Parser<Token, A> = (Tokens) -> (A, Tokens)? | |
struct Parser<Tokens, A> { | |
let parse: (Tokens) -> (A, Tokens)? | |
} | |
typealias Stream<A> = Parser<String.CharacterView, A> |
// | |
// ViewController.swift | |
// BehaviorsDemo | |
// | |
// Created by Saul Mora on 8/25/16. | |
// Copyright © 2016 Magical Panda. All rights reserved. | |
// | |
import UIKit |
let filtered = (1..<1000).filter { | |
$0 % 3 == 0 || $0 % 5 == 0 | |
} | |
filtered.reduce(0, combine: +) |
try { | |
UIALogger.logStart("Testing creating a new playlist") | |
var target = UIATarget.localTarget() | |
var app = target.frontMostApp() | |
var window = app.mainWindow() | |
UIALogger.logMessage("Ensure we are at Mine section by ...") | |
I hereby claim:
To claim this, I am signing this object: