<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main/filter.go
blob: 95e6d82a149bacd509669441168656e3f58dac25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main

type PathFilter struct {
	initial PathFilterState
}
func (filter PathFilter) exec(state *ProgramState) bool {
	pathFilterState := make(map[PathFilterState]struct{})
	pathFilterState[filter.initial] = struct{}{}
	for _, segment := range state.space.path {
		nextPathFilterState := make(map[PathFilterState]struct{})
		for curState := range pathFilterState {
			for nextState := range curState.eat(segment) {
				nextPathFilterState[nextState] = struct{}{}
			}
		}
		pathFilterState = nextPathFilterState
	}
	for pathState := range pathFilterState {
		if pathState.accept() {
			return true
		}
	}
	return false
}

type RangeFilter struct {
	start Filter
	end Filter
	active bool
}

type Filter interface {
	exec(*ProgramState) bool
}