这篇看起来很有难度。多次想放弃。慢慢来吧。
不逐段翻译了,自己总结一下。
represents the states reachable from state i by characterσ without consideringε-transitions, and
represents E(i), the ε-closure of state si (Section 5.3.2).
公式看不懂,那个等号右边第一个符号是啥? i 还是 | ? 啥意思?
反正Bn的意思是从i通过σ到达的状态集合(二进制表示),En的意思就是上节那个E(i)
然后又定义了两个相似的东西,Ed和B。
The mechanism to simulate ε-transitions uses a precomputed tableEd.Ed is built such that, for each possible bit mask of active states, it yields the new set of active states that can be reached from the original ones byε-transitions. This includes the original states and also the initial state 0 and itsε-closure, so as to simulate, without any extra work, the self-loop at the initial state.
The idea for B is to ignore the originating states ofBn, that is, we store inB[σ] all the states that can be reached by the characterσ, from any state:
这个Ed[D]看到这儿时,看不太懂,后边举例时才懂。
B就是所有能通过σ到达的状态集合(当然也是二进制表示)。
作者给了构造Ed和B的算法伪代码
BuildEps(N = (Qn, Σ, In, Fn, Bn, En)) 1. For σ ∈ Σ Do 2. B[σ] ← 0L 3. For i ∈ 0 ... L - 1 Do B[σ] ← B[σ] | Bn[i, σ] 4. End of for /* B is already built, now build Ed */ 5. Ed[0] ← En[0] /* the initial state and its closure */ 6. For i ∈ 0 ... L - 1 Do 7. For j ∈ 0 ... 2i - 1 Do /* recall that En[i] includes i */ 8. Ed[2i + j] ← En[i] Ed[j] 9. End of for 10. End of for 11. Return (B, Ed)
我反正目前看不懂
BPThompson(N = Qn, Σ, In, Fn, Bn, En), T = t1t2 ... tn) 1. preprocessing 2. (B, Ed) ← BuildEps(N) 3. Searching 4. D ← Ed[In] /* the initial state */ 5. For pos ∈ 1 ... n Do 6. If D & Fn ≠ 0L Then report an occurrence ending at pos - 1 7. D ← Ed [(D<<1) & B[tpos]] 8. End of for
Figure 5.16: Thompson's bit-parallel search algorithm
Thompson's bit-parallel search algorithm的伪代码这里是关键。注意关键的一步D← Ed [(D<<1) &B[tpos]]。
For instance, in Figure 5.5 we would have En[3] = 100001001110001000 andEn[11] = 111001101100000000, soEd1[000001000] = 100001001110001000 andEd2[000000100] = 111001101100000000. Thus,Ed[000000100000001000] = 111001101110001000.
将Ed分开可以减少空间
之后是一个实例,图太多了。不拷了。。。
这个算法的大体步骤是。
1 首先计算出,B[σ]和En。
B[σ]就是所有通过σ可以到达的状态集合。当E(s)不等于{s}时,En=E(s);否则,En=E(0)U{s}。(这里有点奇怪,跟这一篇最开始的定义不一样,是我弄错了?)
2 然后计算Ed表
分解成Ed1和Ed2的分开存储的方法不会,不过可以这么算:把Ed里每一位代表的状态的En或起来。例如,Ed[000000000001000100]=En[2] | En[6] = 0000000000000010111 | 100001001111010011 = 100001001111010111
3 初始D为Ed[0]
4 检测D的目标位是否是1(也就是检测是否达到目标状态),达到了,标记。
5 读一个字符D ← Ed [(D<<1) & B[tpos]],goto 第四步。如果没有字符了,结束。
错了的话欢迎指正