Trying something out; we'll see if it works

remotes/origin/implementPCREMatchingRules
Aadhavan Srinivasan 1 month ago
parent bc32e0cb76
commit fbc9dfcc95

@ -15,8 +15,8 @@ const (
func getPriority(state *nfaState) int {
if state.isKleene {
return kleene_priority
} else if state.isQuestion || state.isAlternation {
return zerostate_priority
} else if state.isAlternation {
return alternation_priority
} else {
if state.isEmpty {
@ -33,6 +33,14 @@ type priorQueueItem struct {
index int
}
func newPriorQueueItem(state *nfaState) *priorQueueItem {
return &priorQueueItem{
state: state,
index: -1,
priority: getPriority(state),
}
}
type priorityQueue []*priorQueueItem
func (pq priorityQueue) Len() int {
@ -41,7 +49,7 @@ func (pq priorityQueue) Len() int {
func (pq priorityQueue) Less(i, j int) bool {
if pq[i].priority == pq[j].priority {
return pq[i].index > pq[j].index
return pq[i].index < pq[j].index
}
return pq[i].priority > pq[j].priority // We want max-heap, so we use greater-than
}
@ -68,6 +76,11 @@ func (pq *priorityQueue) Pop() any {
*pq = old[0 : n-1]
return item
}
func (pq *priorityQueue) peek() any {
queue := *pq
n := len(queue)
return queue[n-1]
}
func (pq *priorityQueue) update(item *priorQueueItem, value *nfaState, priority int) {
item.state = value

Loading…
Cancel
Save