ForPosition returns attribute index that apply to the specified position. Returns ErrNotFound when the requested position wasn't found in any of the known ranges.
(pos int)
| 75 | // Returns ErrNotFound when the requested position wasn't found in any of the |
| 76 | // known ranges. |
| 77 | func (t *Tracker) ForPosition(pos int) (*AttrRange, error) { |
| 78 | if ar, ok := t.ranges[pos]; ok { |
| 79 | return ar, nil |
| 80 | } |
| 81 | |
| 82 | var keys []int |
| 83 | for k := range t.ranges { |
| 84 | keys = append(keys, k) |
| 85 | } |
| 86 | sort.Ints(keys) |
| 87 | |
| 88 | var res *AttrRange |
| 89 | for _, k := range keys { |
| 90 | ar := t.ranges[k] |
| 91 | if ar.Low > pos { |
| 92 | break |
| 93 | } |
| 94 | if ar.High > pos { |
| 95 | res = ar |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | if res == nil { |
| 100 | return nil, fmt.Errorf("did not find attribute range for position %d", pos) |
| 101 | } |
| 102 | return res, nil |
| 103 | } |
no outgoing calls