Пример #1
0
func RangeUsedUpdate(taskRanges *mesosproto.Value_Ranges, nodeRanges *mesosproto.Value_Ranges) *mesosproto.Value_Ranges {
	var newNodeRanges []*mesosproto.Value_Range
	for _, taskRange := range taskRanges.GetRange() {
		for _, nodeRange := range nodeRanges.GetRange() {
			if RangeInside(nodeRange, taskRange) {
				subedLeftRange, subedRightRange := RangeSub(nodeRange, taskRange)
				if subedLeftRange != nil {
					newNodeRanges = append(newNodeRanges, subedLeftRange)
				}
				if subedRightRange != nil {
					newNodeRanges = append(newNodeRanges, subedRightRange)
				}
			}
		}
	}
	return &mesosproto.Value_Ranges{
		Range: newNodeRanges,
	}
}
Пример #2
0
func RangeAdd(rangeOne *mesosproto.Value_Ranges, rangeTwo *mesosproto.Value_Ranges) *mesosproto.Value_Ranges {
	line := make([]bool, 65536)
	for _, enumRange := range rangeOne.GetRange() {
		for index := enumRange.GetBegin(); index <= enumRange.GetEnd(); index++ {
			line[index] = true
		}
	}

	for _, enumRange := range rangeTwo.GetRange() {
		for index := enumRange.GetBegin(); index <= enumRange.GetEnd(); index++ {
			line[index] = true
		}
	}

	newRanges := &mesosproto.Value_Ranges{}
	for index := 0; index < len(line); {
		for index < len(line) && !line[index] {
			index++
		}
		if index < len(line) {
			uint64Begin := uint64(index)
			newRange := &mesosproto.Value_Range{
				Begin: &uint64Begin,
			}

			for index < len(line) && line[index] {
				index++
			}
			uint64End := uint64(index - 1)
			newRange.End = &uint64End
			newRanges.Range = append(newRanges.Range, newRange)
		}
	}

	return newRanges
}