Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Dec 20, 2024
1 parent 092ae4c commit d0c61fc
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,42 @@ extension P {
}

struct PBuffer {
var startIndex: UnsafeHeterogeneousBuffer.Index { contents.startIndex }
var endIndex: UnsafeHeterogeneousBuffer.Index { contents.endIndex }

var contents: UnsafeHeterogeneousBuffer

mutating func append<T>(_ t: T) -> UnsafeHeterogeneousBuffer.Index where T: P {
contents.append(t, vtable: _VTable<T>.self)
}

subscript<T>(_ type: T.Type) -> UnsafeMutablePointer<T>? where T: P {
guard !contents.isEmpty else { return nil }
for elelement in contents {
guard elelement.hasType(type) else {
continue
}
return elelement.body(as: type)
}
return nil
}

typealias Index = UnsafeHeterogeneousBuffer.Index

struct Element {
var base: UnsafeHeterogeneousBuffer.Element
}

var startIndex: UnsafeHeterogeneousBuffer.Index { contents.startIndex }

var endIndex: UnsafeHeterogeneousBuffer.Index { contents.endIndex }

var isEmpty: Bool { contents.isEmpty }

subscript(position: UnsafeHeterogeneousBuffer.Index) -> Element {
_read { yield Element(base: contents[position]) }
}

func index(after i: UnsafeHeterogeneousBuffer.Index) -> UnsafeHeterogeneousBuffer.Index {
contents.index(after: i)
}

private class VTable: _UnsafeHeterogeneousBuffer_VTable {
class func modify(elt: UnsafeHeterogeneousBuffer.Element, inputs: inout Int) {}
Expand Down

0 comments on commit d0c61fc

Please sign in to comment.