Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

ApolloZhu/struct-LinkedList-enum-Node

Repository files navigation

struct LinkedList enum Node

Singly linked list in Swift, but you get a value type instead. What a terrible idea.

public struct LinkedList<Element> {
    private enum Node {
        case value(Element)
        indirect case node(value: Element, next: Node)
    }
}

And this, of course, is not a new idea. It has been explored in posts like What are indirect enums? or Swift Algorithm Club: Swift Binary Search Tree Data Structure. But I only saw them after writing all the code ヽ( ̄~ ̄)ノ Anyways, good linked list practice, I guess.

Road Map

  • CustomDebugStringConvertible
  • CustomReflectable
  • CustomStringConvertible
  • CVarArg
    Declaring conformance to the CVarArg protocol for types defined outside the standard library is not supported.
    
  • Decodable when Element conforms to Decodable.
  • Encodable when Element conforms to Encodable.
  • Equatable when Element conforms to Equatable.
  • ExpressibleByArrayLiteral
  • Hashable when Element conforms to Hashable.
  • MutableCollection
    • Benchmark Sequence conformance performance
    • Benchmark Collection conformance performance
    • Benchmark MutableCollection conformance performance
    • Implement some methods that usually requires BidirectionalCollection
      • reversed
      • ...
  • RangeReplaceableCollection
    • Benchmark, since default implementations are of real nightmare
  • Try to be like Array

About

Pure value type linked list in Swift

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages