Skip to content

Instantly share code, notes, and snippets.

View CTMacUser's full-sized avatar

Daryle Walker CTMacUser

View GitHub Profile
@CTMacUser
CTMacUser / LeftOpenRange.swift
Last active April 16, 2018 02:02
Linked-List Protocol and Singly-Linked List Type in Swift
//
// LeftOpenRange.swift
// NodeCollections
//
// Created by Daryle Walker on 4/6/18.
// Copyright © 2018 Daryle Walker. All rights reserved.
//
// MARK: Primary Definitions
@CTMacUser
CTMacUser / SinglyLinkedList.swift
Created March 19, 2018 01:16
A quick & dirty singly-linked list in Swift 4.
/// A singly-linked list.
public final class SinglyLinkedList<T>: RangeReplaceableCollection, MutableCollection {
/// A node for a singly-linked list.
final class Node {
/// The node's data. May be absent (like for sentinel nodes).
var value: T?
/// The link to the next node, or `nil` when none.
var next: Node!
@CTMacUser
CTMacUser / BinaryInteger+Extensions.swift
Last active February 14, 2018 20:01
(See "UInt72.swift.") An unsigned integer type larger than the one from the Standard Library.
/*
BinaryInteger+Extensions.swift
Created by Daryle Walker on 1/29/18.
Copyright (c) 2018 Daryle Walker.
Distributed under the MIT License.
Various properties and methods for BitArray's bit-twiddling.
@CTMacUser
CTMacUser / Stern-Calkin-Wilf-sequences.swift
Created January 1, 2018 22:21
Stern's Diatomic and the Calkin–Wilf Sequences in Swift
// Copyright (c) 2018 Daryle Walker.
// Distributed under the MIT License.
// Based off <https://en.wikipedia.org/wiki/Calkin–Wilf_tree>.
// "fusc" from Edsger W. Dijkstra.
// To-Do: Add the iterative version of "fusc"
struct SternDiatomicSequenceIterator: IteratorProtocol {
var cache = [0: 0, 1: 1]
@CTMacUser
CTMacUser / NNNN-entity-duplication.md
Last active August 8, 2017 16:23
Swift proposal for a "macro" for generating comma-separated lists.

Entity Duplication

Introduction

This is a proposal to add a macro-like facility to automatically create lists.

@CTMacUser
CTMacUser / NNNN-fixed-size-arrays.md
Last active April 28, 2021 17:37
Swift proposal for fixed-size array types
@CTMacUser
CTMacUser / NNNN-alternative-types.md
Last active July 29, 2017 05:45
Swift proposal for strong type-aliases

Alternative Interface Value Types

Introduction

This proposal adds a nominal type whose structure is an existing value type and interface can be customized, including selective use of the original type's interface. It is equivalent to the type declaration feature in Go, newtype in Haskell, and the oft-requested "strong typedef" in C(++).

@CTMacUser
CTMacUser / NNNN-local-object-aliases.md
Last active June 28, 2017 16:53
Swift proposal for object aliases
@CTMacUser
CTMacUser / Mismatch.swift
Created July 6, 2016 00:40
Proposal and Code to add C++'s mismatch algorithm to Swift.
extension CollectionType {
func diverges<PossiblePrefix: CollectionType where PossiblePrefix.Generator.Element == Generator.Element>(from possiblePrefix: PossiblePrefix, isEquivalent: (Generator.Element, Generator.Element) throws -> Bool) rethrows -> (Index, PossiblePrefix.Index) {
var selfIndex = startIndex
var fromIndex = possiblePrefix.startIndex
while selfIndex != endIndex && fromIndex != possiblePrefix.endIndex {
let areEqual = try isEquivalent(self[selfIndex], possiblePrefix[fromIndex])
guard areEqual else {
break
}
@CTMacUser
CTMacUser / AdjacentDifference.swift
Last active March 23, 2016 22:30
Using Swift to demonstrate finding powers with just adding (and some prep work).
import Foundation
/**
A generator for the distance between two adjacent elements from another generator.
*/
public struct AdjacentDifferenceGenerator<Source: GeneratorType where Source.Element: Strideable>: GeneratorType {
/// The last value read, needed to calculate the difference
private var queue: (Source.Element?, Source.Element?)