Swiftpack.co - Li-Bot/DSKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Li-Bot.
Li-Bot/DSKit 0.2.0
Data Structures written in Swift
⭐️ 1
🕓 3 years ago
iOS
.package(url: "https://github.com/Li-Bot/DSKit.git", from: "0.2.0")

Carthage compatible Pods compatible SPM compatible Swift Version Platform PRs Welcome

DSKit

DSKit is a Framework of Data Structures written in Swift.

Contents

Features

  • ☑ Linked List
  • ☑ Queue
  • ☑ QuadTree

Requirements

  • iOS 8+ / macOS 10.10+
  • Xcode 10+
  • Swift 5+

Installation

Carthage

github "Li-Bot/DSKit.git" ~> 0.1.0

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/Li-Bot/DSKit.git", .upToNextMajor(from: "1.0.0"))
]

Cocoapods

pod 'DSKitc', '~> 0.1.0'

Usage

Let's look at how simple it is!

Linked List

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)

Queue

A simple queue.

// Create
let queue = DSQueue<Int>()
// Enqueue
queue.enqueue(1)
// Dequeue
let firstNumber = queue.dequeue()

QuadTree

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)

QaudTree Image Renderer

Render QuadTree into an image.

let renderer = DSQuadTreeRenderer()
let image = renderer.draw(tree: quadTree, highlight: circle)

Future

  • More data structures. I am only in the beginning.

License

DSKit is released under the GNU GPLv3 license. See the LICENSE here.

GitHub

link
Stars: 1
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics