Closed n4o847 closed 3 years ago
プルリクのときに気づかなかった……
while (queue.length !== 0) {
const source = queue.shift()!;
newStateList.push(source);
if (pnfa.acceptingStateSet.has(source)) {
newAcceptingStateSet.add(source);
}
for (const [_, dests] of pnfa.transitions.getTransitions(source)) {
for (const dest of dests) {
if (!visited.has(dest)) {
visited.add(dest);
queue.push(dest);
}
}
}
}
みたいな修正で良ければこっちでやっておきます
と思ったけど newStateList.push(source)
の位置があってるかわからん……
終了条件が無いから newStateList.push(source)
はどこでもいいのか(ですか?)
これ、pushしたときにtrueにしないと同じStateが複数pushされますね、誠に申し訳ないです、vizで二重辺になってたのそう言うことか あと、この実装だと最初のinitialStateたちをすべてvisited trueにする必要がありそうです。
てかもっと簡単な方法があって
while (queue.length !== 0) {
const source = queue.shift()!;
ここに既に訪れてたらcontinueを入れる
visited.set(source, true);
newStateList.push(source);
if (pnfa.acceptingStateSet.has(source)) {
newAcceptingStateSet.add(source);
}
for (const [_, dests] of pnfa.transitions.getTransitions(source)) {
for (const dest of dests) {
if (!visited.get(dest)!) {
queue.push(dest);
}
}
}
}
あと、この実装だと最初のinitialStateたちをすべてvisited trueにする必要がありそうです。
たしかに(そしたら yuziroppe さんに任せたほうが良いのか、良いですか…?)
てかもっと簡単な方法があって
たしかに?
でもそれだと訪問判定2回やるの無駄感ありませんか
ううう、二回やるの無駄感、たしかに、、、、 自分で書いたコードですし、責任持って直します!報告ありがとうございます
prune
をしたあとstateList
に同じ状態が複数入っていることがあるのが謎で色々見てみたんですが、removeUnreachableState
の中のhttps://github.com/n4o847/seccamp-redos/blob/153cfb431283ae32b90ef2bb9e573a4a921c7cac/src/pruning.ts#L93-L109
で
visited
をqueue
から出してからtrue
にしていますが、queue
に入れるときにtrue
にしなければいけないのでは?と思いましたあと
visited
はSet
に置き換えられると思います。