Skip to content

Instantly share code, notes, and snippets.

Dave Abrahams dabrahams

Block or report user

Report or block dabrahams

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View LongForm.swift
/*
On 64-bit platforms, the discriminator is the most significant 4 bits of the
bridge object.
┌─────────────────────╥─────┬─────┬─────┬─────┐
│ Form ║ b63 │ b62 │ b61 │ b60 │
╞═════════════════════╬═════╪═════╪═════╪═════╡
│ Immortal, Small ║ 1 │ASCII│ 1 │ 0 │
├─────────────────────╫─────┼─────┼─────┼─────┤
View trash
#!/usr/bin/env python
import os
import sys
import subprocess
if len(sys.argv) > 1:
files = []
for arg in sys.argv[1:]:
if os.path.exists(arg):
p = os.path.abspath(arg).replace('\\', '\\\\').replace('"', '\\"')
@dabrahams
dabrahams / Algorithms.swift
Created Jun 8, 2018
Heap extensions to standalone Algorithms prototype
View Algorithms.swift
//===--- Algorithms.swift.gyb ---------------------------------*- swift -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
@dabrahams
dabrahams / BitArray.swift
Created Mar 24, 2018
A mutable collection adapter that projects out each bit of the underlying integers.
View BitArray.swift
struct BitArray<Base : RandomAccessCollection & MutableCollection>
: RandomAccessCollection & MutableCollection
where Base.Element : FixedWidthInteger
{
fileprivate var base: Base
private var bitWidth: Int { return Base.Element.bitWidth }
var startIndex: Int { return 0 }
var endIndex: Int { return Base.Element.bitWidth * base.count }
@dabrahams
dabrahams / MultipassSequence2.swift
Created Mar 15, 2018
Demonstrate a multipass sequence index that doesn't store the Element
View MultipassSequence2.swift
/// A default index type for a type that only supplies
/// `IteratorProtocol` conformance and value semantics
enum SequenceIndex<Base: Sequence> : Comparable {
init() { self = .end }
init(_ s: Base) {
self = .normal(0, s.makeIterator())
}
@dabrahams
dabrahams / MultipassSequence2.swift
Created Mar 15, 2018
Demonstrate a multipass sequence index that doesn't store the Element
View MultipassSequence2.swift
/// A default index type for a type that only supplies
/// `IteratorProtocol` conformance and value semantics
enum SequenceIndex<Base: Sequence> : Comparable {
init() { self = .end }
init(_ s: Base) {
self = .normal(0, s.makeIterator())
}
View MyPrefixWhile.swift
public struct MyPrefixWhile<Base: Sequence> : Sequence {
var predicate: (Base.Element)->Bool
var base: Base
public struct Iterator : IteratorProtocol {
var predicate: (Base.Element)->Bool
var base: Base.Iterator?
public mutating func next() -> Base.Element? {
guard let r = base?.next() else { return nil }
if predicate(r) { return r }
@dabrahams
dabrahams / metalMPI.swift
Last active Jun 9, 2017
Metal MPI Datatype Analogy
View metalMPI.swift
protocol Computation {
associatedtype Input
associatedtype Output
}
struct Map<C: Computation, F: Computation> : Computation
where C.Output : Collection,
C.Output.Element : Numeric, F.Input == C.Output.Element {
typealias Output = MetalArray<F.Output>
typealias Input = C
@dabrahams
dabrahams / MutableBidirectionalRangeReplaceableZip.swift
Created May 26, 2017
Mutable Bidirectional RangeReplaceable Zip
View MutableBidirectionalRangeReplaceableZip.swift
struct MutableBidirectionalRangeReplaceableZip2<
First : BidirectionalCollection
& RangeReplaceableCollection
& MutableCollection,
Second : BidirectionalCollection
& RangeReplaceableCollection
& MutableCollection
> {
var first: First, second: Second
init(first: First, second: Second) {
@dabrahams
dabrahams / UIntBuffer.swift
Last active Apr 25, 2017
A lightweight RangeReplaceableCollection of UnsignedInteger that uses a larger UnsignedInteger for its storage
View UIntBuffer.swift
//===--- UIntBuffer.swift -------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
You can’t perform that action at this time.