protected Lifespan truncateSoonestDefined(Lifespan span, AbstractDBTraceCodeUnit<?> extending,
			AddressRange range) throws CodeUnitInsertionException {
		final Lifespan toScan;
		if (extending == null) {
			toScan = span;
		}
		else if (span.lmax() <= extending.getEndSnap()) {
			// we're shrinking or staying the same, so not possible to collide with others
			return span;
		}
		else {
			toScan = span.withMin(extending.getEndSnap() + 1);
		}
		T truncateBy =
			mapSpace.reduce(TraceAddressSnapRangeQuery.intersecting(range, toScan)
					.starting(Rectangle2DDirection.BOTTOMMOST))
					.firstValue();
		if (truncateBy == null) {
			return span;
		}
		if (truncateBy.getStartSnap() <= span.lmin()) {
			throw new CodeUnitInsertionException("Code units cannot overlap");
		}
		return span.withMax(truncateBy.getStartSnap() - 1);
	}
Select a sub-lifespan from that given so that the box does not overlap an existing unit

<p>
The selected lifespan will have the same start snap as that given. The box is the bounding
box of a unit the client is trying to create.

@param span the lifespan of the box
@param extending if applicable, the unit whose lifespan is being extended
@param range the address range of the box
@return the selected sub-lifespan
@throws CodeUnitInsertionException if the start snap is contained in an existing unit
Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/AbstractBaseDBTraceDefinedUnitsView.java