ranges/ranges.go
func (l *InclusiveRanges) AppendUnique(start, end, step int) {
	if step == 0 {
		return
	}

	subStart := start
	subEnd := start
	subStep := step
	last := start
	pending := 0 // Track unique value count

	// Handle loop test for both increasing
	// and decreasing ranges
	var pred func() bool
	if start <= end {
		if step < 0 {
			step *= -1
		}
		pred = func() bool { return subEnd <= end }
	} else {
		if step > 0 {
			step *= -1
		}
		pred = func() bool { return subEnd >= end }
	}

	// Short-circuit if this is the first range being added
	if len(l.blocks) == 0 {
		l.Append(start, end, step)
		return
	}

	// TODO: More intelligent fast-paths for easy-to-identify
	// overlapping ranges. Such as when the existing range is:
	// 1-100x1 and we are appending 50-150x1. Should be easy
	// enough to just know we can Append(101,150,1)

	for ; pred(); subEnd += step {
		if !l.Contains(subEnd) {
			// Is a unique value in the range
			last = subEnd
			if pending == 0 {
				subStart = last
			}
			pending++
			continue
		}

		if pending == 0 {
			// Nothing to add yet
			continue
		}

		// Current value is already in range.
		// Add previous values
		l.Append(subStart, last, subStep)
		subStart = subEnd + step
		pending = 0
	}

	// Flush the remaining values
	if pending > 0 {
		l.Append(subStart, last, subStep)
	}
}
func (l *InclusiveRanges) AppendUnique(start, end, step int) {
	if step == 0 {
		return
	}

	subStart := start
	subEnd := start
	subStep := step
	last := start
	pending := 0 // Track unique value count

	// Handle loop test for both increasing
	// and decreasing ranges
	var pred func() bool
	if start <= end {
		if step < 0 {
			step *= -1
		}
		pred = func() bool { return subEnd <= end }
	} else {
		if step > 0 {
			step *= -1
		}
		pred = func() bool { return subEnd >= end }
	}

	// Short-circuit if this is the first range being added
	if len(l.blocks) == 0 {
		l.Append(start, end, step)
		return
	}

	// TODO: More intelligent fast-paths for easy-to-identify
	// overlapping ranges. Such as when the existing range is:
	// 1-100x1 and we are appending 50-150x1. Should be easy
	// enough to just know we can Append(101,150,1)

	for ; pred(); subEnd += step {
		if !l.Contains(subEnd) {
			// Is a unique value in the range
			last = subEnd
			if pending == 0 {
				subStart = last
			}
			pending++
			continue
		}

		if pending == 0 {
			// Nothing to add yet
			continue
		}

		// Current value is already in range.
		// Add previous values
		l.Append(subStart, last, subStep)
		subStart = subEnd + step
		pending = 0
	}

	// Flush the remaining values
	if pending > 0 {
		l.Append(subStart, last, subStep)
	}
}
// AppendUnique creates and adds another range of values
// to the total range list. Only unique values from the
// given range are appended to the total range.