Swift implementation of the longest common subsequence (LCS) algorithm for comparing collections.
SwiftLCS is a Swift library that extends the `Collection` protocol to find the longest common subsequence (LCS) between two collections. It solves the classic LCS problem, which is fundamental for comparing sequences in applications like diffing tools, version control systems, and data analysis. The library provides methods such as `longestCommonSubsequence` and `diff` to work with strings, arrays, and other collection types.
Swift developers working on iOS, macOS, or other Swift projects who need to compare sequences, such as those building diffing utilities, version control features, or data analysis tools. It is also suitable for developers requiring Objective-C compatibility in sequence comparisons.
Developers choose SwiftLCS for its clean, Swifty API that integrates seamlessly with Swift's `Collection` protocol, offering out-of-the-box support for strings and arrays. Its unique selling point is providing both the LCS result and detailed index diffing (common, added, removed) in a single library, with considerations for Objective-C object comparison.
Swift implementation of the longest common subsequence (LCS) algorithm.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Extends Swift's Collection protocol directly, allowing methods like longestCommonSubsequence to be called on any collection type, as demonstrated with strings and arrays in the usage examples.
The diff method returns indexes for common, added, and removed elements, providing granular data useful for UI updates or analytics, shown in the array index example in the README.
Supports comparison of Objective-C objects via the isEquals: method, making it suitable for mixed Swift-Objective-C projects, as noted in the warning section.
Available via CocoaPods, Carthage, Swift Package Manager, and manual inclusion, ensuring easy integration into various project setups, detailed in the installation section.
Relies on correct isEquals: implementation for Objective-C objects, which can lead to subtle bugs and incorrect indexes if not properly handled, as explicitly warned in the README.
Implements the standard LCS algorithm with O(n*m) time and space complexity, which may become a bottleneck for very large sequences, though not discussed in the documentation.
Focuses only on LCS and basic index diffing, lacking built-in support for more complex operations like applying diffs, handling moves, or visual diffing, requiring additional work for advanced use cases.