예제 #1
0
func Load(ls *persist.LoadSaver) core.Matcher {
	le := ls.LoadSmallInt()
	if le == 0 {
		return nil
	}
	riffs := make(map[riff.FourCC][]int)
	for i := 0; i < le; i++ {
		k := riff.FourCC(ls.LoadFourCC())
		r := make([]int, ls.LoadSmallInt())
		for j := range r {
			r[j] = ls.LoadSmallInt()
		}
		riffs[k] = r
	}
	return &Matcher{
		riffs:      riffs,
		priorities: priority.Load(ls),
	}
}
예제 #2
0
func Add(c core.Matcher, ss core.SignatureSet, p priority.List) (core.Matcher, int, error) {
	sigs, ok := ss.(SignatureSet)
	if !ok {
		return nil, -1, fmt.Errorf("RIFFmatcher: can't cast persist set")
	}
	if len(sigs) == 0 {
		return c, 0, nil
	}
	var m *Matcher
	if c == nil {
		m = &Matcher{
			riffs:      make(map[riff.FourCC][]int),
			priorities: &priority.Set{},
		}
	} else {
		m = c.(*Matcher)
	}
	var length int
	// unless it is a new matcher, calculate current length by iterating through all the result values
	if len(m.riffs) > 0 {
		for _, v := range m.riffs {
			for _, w := range v {
				if w > length {
					length = w
				}
			}
		}
		length++ // add one - because the result values are indexes
	}
	for i, v := range sigs {
		cc := riff.FourCC(v)
		_, ok := m.riffs[cc]
		if ok {
			m.riffs[cc] = append(m.riffs[cc], i+length)
		} else {
			m.riffs[cc] = []int{i + length}
		}
	}
	// add priorities
	m.priorities.Add(p, len(sigs), 0, 0)
	return m, length + len(sigs), nil
}