Example #1
0
func recursive_each(n trie.Node, proc func(trie.Node)) {
	n.Each(func(m trie.Node) bool {
		proc(m)
		recursive_each(m, proc)
		return true
	})
}
Example #2
0
// splitLabels split children which have children or not.
func (m *matcher) splitLabels(n trie.Node) (label string, nodes *list.List) {
	l := list.New()
	b := new(bytes.Buffer)
	n.Each(func(t trie.Node) bool {
		if t.HasChildren() {
			l.PushBack(t)
		} else {
			b.WriteRune(t.Label())
		}
		return true
	})
	return b.String(), l
}
Example #3
0
func checkNode(t *testing.T, node trie.Node, size int, data nodeData) {
	if node == nil {
		t.Error("Nil node:", data)
	}
	if node.Size() != size {
		t.Errorf("Unexpected childrens: %d != %d", node.Size(), size)
	}
	d := node.Value().(*nodeData)
	if d == nil {
		t.Error("Nil data:", data, node)
	}
	if data.pattern != nil && *d.pattern != *data.pattern {
		t.Error("Pattern unmatched:", data, node, *d.pattern)
	}
	if data.value != nil && d.value != data.value {
		t.Error("Value unmatched:", data, node, d.value)
	}
	if d.failure == nil {
		t.Error("Nil failure:", data, node)
	} else if d.failure != data.failure {
		t.Errorf("Failure unmatched: data=%+v node=%+v d.failure=%+v",
			data, node, d.failure)
	}
}