Weaver is a Swift package providing a robust collection of fundamental data structures and algorithms. Designed for performance and ease of use, it offers clean, generic implementations of essential building blocks for Swift applications.
The library is organized into logical data structure categories:
- Queue: A generic First-In-First-Out (FIFO) queue implementation supporting efficient enqueue and dequeue operations. It conforms to
ExpressibleByArrayLiteralfor convenient initialization.
- BinaryNode: A simple, generic building block for constructing binary trees.
- Heap: A highly configurable min-priority or max-priority heap (Priority Queue) implementation. It includes automatic
heapifyfunctionality and efficient insertion/extraction.
- DisjointSet: An optimized implementation of the Disjoint-Set (Union-Find) data structure. It features path compression and union-by-rank to provide near-constant time operations for grouping and connectivity checks.
- Grid: A 2D coordinate system utility for managing values in a matrix. It includes built-in support for point-based indexing and calculating adjacent neighbors.
Add Weaver to your project by adding it to your Package.swift dependencies:
dependencies: [
.package(url: "https://github.com/ramble-logic/weaver.git", from: "1.0.0")
]Then, include Weaver in your target's dependencies:
.target(
name: "YourTarget",
dependencies: ["Weaver"]
)let queue: Queue<Int> = [1, 2, 3]
queue.enqueue(4)
let first = queue.dequeue() // 1var minHeap = Heap([3, 1, 4, 2], orientation: .min)
minHeap.insert(0)
let smallest = minHeap.pop() // 0var ds = DisjointSet(size: 10)
ds.union(node1: 1, node2: 2)
let isConnected = ds.connected(node1: 1, node2: 2) // truelet matrix = [
[1, 2],
[3, 4]
]
let grid = Grid(matrix)
let neighbors = grid.adjacent(to: Point(i: 0, j: 0)) // [Point(i: 1, j: 0), Point(i: 0, j: 1)]Weaver has no external dependencies beyond the Swift Standard Library and Foundation.
This project is maintained by Ramble Logic.