func (v *Vector) Set(i int, e Equaler) {
	if i < v.min.pos || v.max.pos <= i {
		if !v.Relaxed {
			panic(ErrOutOfRange)
		}
		if i < v.min.pos {
			if i == v.min.pos-1 {
				if e.Equal(v.min.val) {
					v.min.pos--
				} else {
					v.min = &position{pos: i, val: e}
					v.t.Insert(v.min)
				}
			} else {
				if v.min.val.Equal(v.Zero) {
					v.min.pos = i + 1
				} else {
					v.min = &position{pos: i + 1, val: v.Zero}
					v.t.Insert(v.min)
				}
				if e.Equal(v.Zero) {
					v.min.pos--
				} else {
					v.min = &position{pos: i, val: e}
					v.t.Insert(v.min)
				}
			}
		} else if i >= v.max.pos {
			if i == v.max.pos {
				v.max.pos++
				prev := v.t.Floor(query(i)).(*position)
				if !e.Equal(prev.val) {
					v.t.Insert(&position{pos: i, val: e})
				}
			} else {
				mpos := v.max.pos
				v.max.pos = i + 1
				prev := v.t.Floor(query(i)).(*position)
				if !prev.val.Equal(v.Zero) {
					v.t.Insert(&position{pos: mpos, val: v.Zero})
				}
				if !e.Equal(v.Zero) {
					v.t.Insert(&position{pos: i, val: e})
				}
			}
		}
		return
	}
	lo := v.t.Floor(query(i)).(*position)
	if e.Equal(lo.val) {
		return
	}
	hi := v.t.Ceil(upper(i)).(*position)
	if lo.pos == i {
		if hi.pos == i+1 {
			if hi != v.max && e.Equal(hi.val) {
				v.t.Delete(query(i))
				hi.pos--
				if v.min.pos == i {
					v.min = hi
				}
			} else {
				lo.val = e
			}
			if i > v.min.pos {
				prev := v.t.Floor(query(i - 1)).(*position)
				if e.Equal(prev.val) {
					v.t.Delete(query(i))
				}
			}
		} else {
			lo.pos = i + 1
			prev := v.t.Floor(query(i))
			if prev == nil {
				v.min = &position{pos: i, val: e}
				v.t.Insert(v.min)
			} else if !e.Equal(prev.(*position).val) {
				v.t.Insert(&position{pos: i, val: e})
			}
		}
	} else {
		if hi.pos == i+1 {
			if hi != v.max && e.Equal(hi.val) {
				hi.pos--
			} else {
				v.t.Insert(&position{pos: i, val: e})
			}
		} else {
			v.t.Insert(&position{pos: i, val: e})
			v.t.Insert(&position{pos: i + 1, val: lo.val})
		}
	}
}
Set sets the value of position i to e.
package step
import (
	"errors"
	"fmt"
	"github.com/biogo/store/llrb"
)
var (
	ErrOutOfRange    = errors.New("step: index out of range")
	ErrInvertedRange = errors.New("step: inverted range")
	ErrZeroLength    = errors.New("step: attempt to create zero length vector")
)
type (
	position struct {
		pos int
		val Equaler
	}
	lower int
	query int
	upper int
)
func (p *position) Compare(c llrb.Comparable) int {
	return p.pos - c.(*position).pos
}
func (q lower) Compare(c llrb.Comparable) (d int) {
	d = int(q) - c.(*position).pos
	if d == 0 {
		d = -1
	}
	return
}
func (q query) Compare(c llrb.Comparable) (d int) {
	switch c := c.(type) {
	case *position:
		d = int(q) - c.pos
	case query:
		d = int(q) - int(c)
	}
	return
}
func (q upper) Compare(c llrb.Comparable) (d int) {
	d = int(q) - c.(*position).pos
	if d == 0 {
		d = 1
	}
	return
}
type Equaler interface {
	Equal(Equaler) bool
}
type Int int
func (i Int) Equal(e Equaler) bool {
	return i == e.(Int)
}
type Float float64
func (f Float) Equal(e Equaler) bool {
	ef := e.(Float)
	if f != f && ef != ef {  
		return true
	}
	return f == ef
}
type Vector struct {
	Zero     Equaler  
	Relaxed  bool     
	t        llrb.Tree
	min, max *position
}
func New(start, end int, zero Equaler) (*Vector, error) {
	if start >= end {
		return nil, ErrZeroLength
	}
	v := &Vector{
		Zero: zero,
		min: &position{
			pos: start,
			val: zero,
		},
		max: &position{
			pos: end,
			val: nil,
		},
	}
	v.t.Insert(v.min)
	v.t.Insert(v.max)
	return v, nil
}
func (v *Vector) Start() int { return v.min.pos }
func (v *Vector) End() int { return v.max.pos }
func (v *Vector) Len() int { return v.End() - v.Start() }
func (v *Vector) Count() int { return v.t.Len() - 1 }
func (v *Vector) At(i int) (Equaler, error) {
	if i < v.Start() || i >= v.End() {
		return nil, ErrOutOfRange
	}
	st := v.t.Floor(query(i)).(*position)
	return st.val, nil
}
func (v *Vector) StepAt(i int) (start, end int, e Equaler, err error) {
	if i < v.Start() || i >= v.End() {
		return 0, 0, nil, ErrOutOfRange
	}
	lo := v.t.Floor(query(i)).(*position)
	hi := v.t.Ceil(upper(i)).(*position)
	return lo.pos, hi.pos, lo.val, nil
}