DSKit is a Framework of Data Structures written in Swift.
- Linked List
- Queue
- QuadTree
- iOS 8+ / macOS 10.10+
- Xcode 10+
- Swift 5+
github "Li-Bot/DSKit.git" ~> 0.1.0
dependencies: [
.package(url: "https://github.com/Li-Bot/DSKit.git", .upToNextMajor(from: "1.0.0"))
]
pod 'DSKitc', '~> 0.1.0'
Let's look at how simple it is!
A simple linked list.
// Create
let list = DSLinkedList<DSLinkedListNode<Int>>()
// Append
list.append(data: 1)
list.append(node: DSLinkedListNode(data: 2))
// Get
let firstNumber = list[0]
// Remove
list.remove(at: 1)
A simple queue.
// Create
let queue = DSQueue<Int>()
// Enqueue
queue.enqueue(1)
// Dequeue
let firstNumber = queue.dequeue()
QuadTree is a special tree data structure. QuadTree is used for spatial decomposition of 2D space. Each node has four subnodes that represent - top left, top right, bottom right and bottom left.
// Create
let treeRootRect = DSQuadRect(origin: .zero, end: CGPoint(x: 100.0, y: 100.0))
let quadTree = DSQuadTree<DSQuadTreeNode<Int>>(rect: treeRootRect)
// Insert
var result = quadTree.insert(node: DSQuadTreeNode(position: CGPoint(x: 10.0, y: 10.0), data: 1))
result = quadTree.insert(node: DSQuadTreeNode(position: CGPoint(x: 12.0, y: 12.0), data: 1))
result = quadTree.insert(node: DSQuadTreeNode(position: CGPoint(x: 70.0, y: 90.0), data: 1))
// Search
let foundNode = quadTree.search(at: CGPoint(x: 10.0, y: 10.0))
let circle = DSCircle(center: CGPoint(x: 50.0, y: 50.0), radius: 25.0)
let foundNodes = quadTree.search(at: circle)
Render QuadTree into an image.
let renderer = DSQuadTreeRenderer()
let image = renderer.draw(tree: quadTree, highlight: circle)
- More data structures. I am only in the beginning.
DSKit is released under the GNU GPLv3 license. See the LICENSE here.