frugghi / swiftlcs Goto Github PK
View Code? Open in Web Editor NEWSwift implementation of the longest common subsequence (LCS) algorithm.
License: MIT License
Swift implementation of the longest common subsequence (LCS) algorithm.
License: MIT License
let first = [0,1,1,2,3]
let second = [0,1,2,3]
let diff = first.diff(second)
print("commonIndexes: \(diff.commonIndexes)")
result in
commonIndexes: [0, 1, 2, 3, 4]
expect: [0, 1, 3, 4] or [0, 2, 3, 4]
Maybe caused by wrong endIndex in prefix func
func prefix(_ otherCollection: Self, count: Int, suffix: Int, by areEquivalent: (Element, Element) -> Bool) -> (Int, [Index]) {
...
let endIndex = self.index(self.startIndex, offsetBy: count - suffix)
let endIndex = self.index(self.startIndex, offsetBy: count - suffix - 1) // maybe???
...
}
Whenever the length of the text is a bit long (about 510 characters) the algorithm crashes in the following function:
and this line: else if table[i][j] == table[i][j-1]
/// Walks back through the generated table to generate the diff.
fileprivate static func diffFromIndices(_ table: [[Int]], _ x: [Element], _ y: [Element], _ i: Int, _ j: Int) -> Diff {
if i == 0 && j == 0 {
return Diff<Element>(results: [])
} else if i == 0 {
return diffFromIndices(table, x, y, i, j-1) + DiffStep.insert(j-1, y[j-1])
} else if j == 0 {
return diffFromIndices(table, x, y, i - 1, j) + DiffStep.delete(i-1, x[i-1])
} else if table[i][j] == table[i][j-1] {
return diffFromIndices(table, x, y, i, j-1) + DiffStep.insert(j-1, y[j-1])
} else if table[i][j] == table[i-1][j] {
return diffFromIndices(table, x, y, i - 1, j) + DiffStep.delete(i-1, x[i-1])
} else {
return diffFromIndices(table, x, y, i-1, j-1)
}
}
let first = [0,1,2]
let second = [0,1,2,3,3]
print(first.diff(second).addedIndexes)
outputs [3, 3]
instead of [3, 4]
SwiftLCS.swift line 116: Conditional downcast from 'Self.Element?' to 'Self.Element' does nothing
It's relating to this downcast:
while let lhs = entry.0 as? Iterator.Element,
Pods/SwiftLCS/SwiftLCS/SwiftLCS.swift:211:28: 'characters' is deprecated: Please use String or Substring directly
For some reason SwiftLCS
does not recognize the two collections as containing common indexes. The two arrays being compared are exactly the same, but SwiftLCS
removes all indexes and adds them back instead of simply recognizing that they are common indexes.
I essentially have a query that pulls all data, and I have SwiftLCS compare the cached data array to the new, in-coming data array.
Any plans of migrating?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.