DesignAlgorithmsKit (DAK) is a general-purpose, domain-agnostic Swift library of reusable design patterns, concurrency helpers and algorithms. It has no dependencies of its own and must not contain file-system, platform, inventory or app concepts; generic code found in packages built on it belongs here.
One library product and target: DesignAlgorithmsKit (Sources/DesignAlgorithmsKit).
| Area | Types |
|---|---|
| Registries | TypeRegistry, Registrable, Registry<Key, Value> |
| Singletons | ThreadSafeSingleton, Singleton, ActorSingleton, SingletonError |
| Factory / builder | ObjectFactory, FactoryProduct, FactoryError, BaseBuilder, BuilderError, ValidatingBuilderProtocol |
| Thread-safe containers | ThreadSafe<Value>, ThreadSafeArray, ThreadSafeDictionary |
| Structural patterns | BaseAdapter, BaseFacade, BaseDecorator, Composite/Leaf/BaseComponent |
| Behavioral patterns | StrategyContext, BaseStrategy, BaseObservable/Observer, CommandInvoker/ClosureCommand, BaseHandler/BaseTypedHandler, ArrayIterator/TreeIterator, Visitor/Visitable, Mergeable/MergeStrategy/DefaultMerger |
| Pipelines | DataPipeline, AsyncDataPipeline, AnyAsyncPipelineStage, DynamicAsyncPipeline, PipelineError |
| Async work | ProcessingQueue/QueueItem/QueueProcessor, JobManager, TaskOrchestrator/DAGTask, ResourceCoordinator |
| Hashing | HashAlgorithm (SHA-256, SHA-1, MD5, CRC-32), HashComputation, HashStrategy/HashStrategyRegistry, SHA256, Data.sha256/sha256Hex, CRC32Checksum (UInt32, incremental) |
| Identifiers | ULID, UUIDv5Generator |
| Probabilistic filters | BloomFilter, CountingBloomFilter, BloomFilterHashable |
| Merkle tree | MerkleTree, MerkleProof, MerkleHashable |
| Graphs | Graph<T> (directed, BFS reachability, unreachable-node detection) |
| Binary data | DataReader (sequential, throwing), BinaryDataReader (big/little-endian at an offset; lenient named readers and checked read/write), BinaryReadError, ByteOrder |
| Compression | Zlib/ZlibError (zlib, gzip and raw DEFLATE framing by window bits, via system zlib), Gzip (in-memory GZIP) |
| Encryption | HybridEncryption (Curve25519 + HKDF-SHA256 + ChaCha20-Poly1305) |
| Text / paths | FilenameTokenizer, StringExtractor (printable runs, like strings), GitObjectLayout, FallbackTextDecoder/TextDecodingStrategy/StringEncodingStrategy/TextDecoderRegistry, Data.decodedText(using:) |
macOS 12 and iOS 15 (swift-tools-version 5.10); CI builds both. The library uses CryptoKit, NSLock and the system zlib, so it builds only for Apple platforms; building without CryptoKit fails with a compile-time error instead of producing placeholder digests. tvOS and watchOS are not declared or built.
- Direct package dependencies: none. The package links the system library
zand uses Foundation and CryptoKit. - Tree (
swift package show-dependencies):DesignAlgorithmsKit └── (no external dependencies) - How consumers reference DAK. The canonical remote is
https://github.com/nibbleware/DesignAlgorithmsKit.git, andrickhohler/DesignAlgorithmsKitredirects to it. Use a semver range:The latest tag is.package(url: "https://github.com/nibbleware/DesignAlgorithmsKit.git", from: "1.13.0")
v1.13.0.
import DesignAlgorithmsKit
// Keyed registry (thread-safe)
final class CodecRegistry: Registry<String, any Codec> {}
let codecs = CodecRegistry()
codecs.register(MyCodec(), for: "my")
// Lazily created, per-type singleton
final class Settings: ThreadSafeSingleton {
override class func createShared() throws -> Settings { Settings() }
}
let settings = Settings.shared
// Hashing
let hex = try HashComputation.computeHashHex(data: data, algorithm: .sha256)
let crc = HashComputation.computeCRC32(data: data) // 4 bytes, big-endian
// Identifiers
let id = UUIDv5Generator.generate(namespace: ns, name: "python.org")
// GZIP
let gz = try Gzip.compress(data: data)
let raw = try Gzip.decompress(data: gz)
// zlib with explicit framing (15 zlib, 31 gzip, -15 raw DEFLATE)
let deflated = try Zlib.compress(data: data, windowBits: -15)
let inflated = try Zlib.decompress(data: deflated, framing: .rawDeflate)
let crc32 = CRC32Checksum.checksum(data) // UInt32
// Text of unknown encoding: US-ASCII, UTF-8, Mac OS Roman, Windows-1252,
// control characters (except newlines and tabs) removed
let text = bytes.decodedText()
// Add your own character sets before or after the defaults
TextDecoderRegistry.shared.register(MyCharsetStrategy(), placement: .beforeDefaults)
let custom = TextDecoderRegistry.shared.decode(bytes)swift build
swift test- No other packages are needed to build DAK.
swift buildis warning-free.swift testruns the unit tests (DesignAlgorithmsKitTests, 374 XCTest tests) and the integration tests (DesignAlgorithmsKitIntegrationTests), which call/usr/bin/gzipand/usr/bin/gunzipand are skipped when those tools are missing.- CI also builds for the iOS Simulator:
xcodebuild build -scheme DesignAlgorithmsKit -destination 'generic/platform=iOS Simulator'.
None known.
Sources/DesignAlgorithmsKit/DesignAlgorithmsKit.docc/: DocC catalog. Build it with Xcode's Product > Build Documentation orxcodebuild docbuild -scheme DesignAlgorithmsKit -destination 'generic/platform=macOS'.- CHANGELOG.md, CONTRIBUTING.md, SECURITY.md, CODE_OF_CONDUCT.md.
MIT. See LICENSE.