ranges/ranges.go
func (l *InclusiveRanges) Value(idx int) (int, error) {
	if idx < 0 {
		return 0, fmt.Errorf("Index %d is not >= 0", idx)
	}

	var err error
	var val, size, n int

	for _, b := range l.blocks {
		size = b.Len()

		// modify the original index to be within
		// the range of the current range block, and
		// then check that it is a valid index value
		if (idx - n) < size {
			if val, err = b.Value(idx - n); err == nil {
				return val, nil
			}
		}

		// record the offset so we can continue to
		// modify the original index value to the local range
		n += size
	}

	// The previous loop ended in error
	return 0, fmt.Errorf("Index %d exceeds the total range", idx)
}
func (l *InclusiveRanges) Value(idx int) (int, error) {
	if idx < 0 {
		return 0, fmt.Errorf("Index %d is not >= 0", idx)
	}

	var err error
	var val, size, n int

	for _, b := range l.blocks {
		size = b.Len()

		// modify the original index to be within
		// the range of the current range block, and
		// then check that it is a valid index value
		if (idx - n) < size {
			if val, err = b.Value(idx - n); err == nil {
				return val, nil
			}
		}

		// record the offset so we can continue to
		// modify the original index value to the local range
		n += size
	}

	// The previous loop ended in error
	return 0, fmt.Errorf("Index %d exceeds the total range", idx)
}
// Value returns the value at the given index in
// the total range. If the index is invalid/exceeds the valid
// range, an error will be returned.