forked from jasder/antlr
[Swift] Change getStateToAltMap to use Int as the dictionary key, not ATNState.
The ATNState hashValue and == override are just using the stateNumber field, so using the Int directly is equivalent, and saves bouncing through those methods. This also seems to be a correctness issue with the new Hashable protocol changes in Swift 4.2 (though I admit that I don't know why). Remove PredictionMode.getStateToAltMap, which was just a stub onto ATNConfigSet.getStateToAltMap and didn't seem to be doing anything useful.
This commit is contained in:
parent
1184c67f72
commit
8cd798431d
|
@ -321,17 +321,17 @@ public class ATNConfigSet: Hashable, CustomStringConvertible {
|
||||||
return Array(configToAlts.values)
|
return Array(configToAlts.values)
|
||||||
}
|
}
|
||||||
|
|
||||||
public final func getStateToAltMap() -> [ATNState: BitSet] {
|
public func getStateToAltMap() -> [Int: BitSet] {
|
||||||
let length = configs.count
|
let length = configs.count
|
||||||
var m = [ATNState: BitSet]()
|
var m = [Int: BitSet]()
|
||||||
|
|
||||||
for i in 0..<length {
|
for i in 0..<length {
|
||||||
var alts: BitSet
|
var alts: BitSet
|
||||||
if let mAlts = m[configs[i].state] {
|
if let mAlts = m[configs[i].state.stateNumber] {
|
||||||
alts = mAlts
|
alts = mAlts
|
||||||
} else {
|
} else {
|
||||||
alts = BitSet()
|
alts = BitSet()
|
||||||
m[configs[i].state] = alts
|
m[configs[i].state.stateNumber] = alts
|
||||||
}
|
}
|
||||||
|
|
||||||
try! alts.set(configs[i].alt)
|
try! alts.set(configs[i].alt)
|
||||||
|
|
|
@ -485,20 +485,8 @@ public enum PredictionMode {
|
||||||
return configs.getConflictingAltSubsets()
|
return configs.getConflictingAltSubsets()
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
|
||||||
/// Get a map from state to alt subset from a configuration set. For each
|
|
||||||
/// configuration `c` in `configs`:
|
|
||||||
///
|
|
||||||
///
|
|
||||||
/// map[c._org.antlr.v4.runtime.atn.ATNConfig#state state_] U= c._org.antlr.v4.runtime.atn.ATNConfig#alt alt_
|
|
||||||
///
|
|
||||||
///
|
|
||||||
public static func getStateToAltMap(_ configs: ATNConfigSet) -> [ATNState: BitSet] {
|
|
||||||
return configs.getStateToAltMap()
|
|
||||||
}
|
|
||||||
|
|
||||||
public static func hasStateAssociatedWithOneAlt(_ configs: ATNConfigSet) -> Bool {
|
public static func hasStateAssociatedWithOneAlt(_ configs: ATNConfigSet) -> Bool {
|
||||||
let x = getStateToAltMap(configs)
|
let x = configs.getStateToAltMap()
|
||||||
for alts in x.values {
|
for alts in x.values {
|
||||||
if alts.cardinality() == 1 {
|
if alts.cardinality() == 1 {
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue