@@ -38,7 +38,7 @@ const valueTerminator byte = 0xf5
3838// but I imagine organizing it this way is a bit more memory-efficient. Suppose we want to model a table where
3939// byte values 3 and 4 map to ss1 and byte 0x34 maps to ss2. Then the smallTable would look like:
4040// ceilings:--|3|----|5|-|0x34|--|x35|-|byteCeiling|
41- // steps:---|nil|-|&ss1|--|ni|- -|&ss2|---------|nil|
41+ // steps:---|nil|-|&ss1|--|nil| -|&ss2|---------|nil|
4242// invariant: The last element of ceilings is always byteCeiling
4343// The motivation is that we want to build a state machine on byte values to implement things like prefixes and
4444// ranges of bytes. This could be done simply with an array of size byteCeiling for each state in the machine,
@@ -133,7 +133,7 @@ func mergeOneDfaStep(step1, step2 *dfaStep, memoize map[dfaStepKey]*dfaStep) *df
133133 uComb [i ] = stepNew
134134 case stepExisting != nil && stepNew != nil :
135135 // there are considerable runs of the same value
136- if i > 1 && stepExisting == uExisting [i - 1 ] && stepNew == uNew [i - 1 ] {
136+ if i > 0 && stepExisting == uExisting [i - 1 ] && stepNew == uNew [i - 1 ] {
137137 uComb [i ] = uComb [i - 1 ]
138138 } else {
139139 uComb [i ] = mergeOneDfaStep (stepExisting , stepNew , memoize )
@@ -148,7 +148,7 @@ func mergeOneDfaStep(step1, step2 *dfaStep, memoize map[dfaStepKey]*dfaStep) *df
148148// transitions in the NFA because, as of the time of writing, none of the
149149// pattern-matching required those transitions. It is based on the algorithm
150150// taught in the TU München course “Automata and Formal Languages”, lecturer
151- // Prof. Dr.Ernst W. Mayr in 2014-15, in particular the examples appearing in
151+ // Prof. Dr. Ernst W. Mayr in 2014-15, in particular the examples appearing in
152152// http://wwwmayr.informatik.tu-muenchen.de/lehre/2014WS/afs/2014-10-14.pdf
153153// especially the slide in Example 11.
154154//
@@ -208,69 +208,6 @@ func nfaStep2DfaStep(stepList *nfaStepList, memoize *dfaMemory) *dfaStep {
208208 return dStep
209209}
210210
211- type nfaStepKey struct {
212- step1 * nfaStep
213- step2 * nfaStep
214- }
215-
216- func mergeNfas (nfa1 , nfa2 * smallTable [* nfaStepList ]) * smallTable [* nfaStepList ] {
217- step1 := & nfaStep {table : nfa1 }
218- step2 := & nfaStep {table : nfa2 }
219- return mergeOneNfaStep (step1 , step2 , make (map [nfaStepKey ]* nfaStep ), newListMaker (), 0 ).table
220- }
221-
222- func mergeOneNfaStep (step1 , step2 * nfaStep , memoize map [nfaStepKey ]* nfaStep , lister * listMaker , depth int ) * nfaStep {
223- var combined * nfaStep
224- mKey := nfaStepKey {step1 : step1 , step2 : step2 }
225- combined , ok := memoize [mKey ]
226- if ok {
227- return combined
228- }
229-
230- newTable := newSmallTable [* nfaStepList ]()
231- switch {
232- case step1 .fieldTransitions == nil && step2 .fieldTransitions == nil :
233- combined = & nfaStep {table : newTable }
234- case step1 .fieldTransitions != nil && step2 .fieldTransitions != nil :
235- transitions := append (step1 .fieldTransitions , step2 .fieldTransitions ... )
236- combined = & nfaStep {table : newTable , fieldTransitions : transitions }
237- case step1 .fieldTransitions != nil && step2 .fieldTransitions == nil :
238- combined = & nfaStep {table : newTable , fieldTransitions : step1 .fieldTransitions }
239- case step1 .fieldTransitions == nil && step2 .fieldTransitions != nil :
240- combined = & nfaStep {table : newTable , fieldTransitions : step2 .fieldTransitions }
241- }
242- memoize [mKey ] = combined
243-
244- u1 := unpackTable (step1 .table )
245- u2 := unpackTable (step2 .table )
246- var uComb unpackedTable [* nfaStepList ]
247- for i , list1 := range u1 {
248- list2 := u2 [i ]
249- switch {
250- case list1 == nil && list2 == nil :
251- uComb [i ] = nil
252- case list1 != nil && list2 == nil :
253- uComb [i ] = u1 [i ]
254- case list1 == nil && list2 != nil :
255- uComb [i ] = u2 [i ]
256- case list1 != nil && list2 != nil :
257- var comboList []* nfaStep
258- for _ , nextStep1 := range list1 .steps {
259- for _ , nextStep2 := range list2 .steps {
260- merged := mergeOneNfaStep (nextStep1 , nextStep2 , memoize , lister , depth + 1 )
261- comboList = append (comboList , merged )
262- }
263- }
264- uComb [i ] = lister .getList (comboList ... )
265- }
266- }
267- combined .table .pack (& uComb )
268- return combined
269- }
270-
271- // TODO: Clean up from here on down - too many funcs doing about the same thing, and also it seems that
272- // we never want to have more than one "range", which is the whole table.
273-
274211// makeSmallDfaTable creates a pre-loaded small table, with all bytes not otherwise specified having the defaultStep
275212// value, and then a few other values with their indexes and values specified in the other two arguments. The
276213// goal is to reduce memory churn
0 commit comments