private int getBaseAddressIndex(Address addr) {

		AddressSpace space = addr.getAddressSpace();
		if (space.isStackSpace()) {
			if (stackSpace != null && !stackSpace.equals(space)) {
				throw new IllegalArgumentException("Only one stack space allowed");
			}
			stackSpace = space;
			return STACK_SPACE_ID;
		}

		long baseOffset = addr.getOffset() & BASE_MASK;

		if (lastBaseIndex >= 0) {
			Address base = baseAddrs[lastBaseIndex];
			if (base.hasSameAddressSpace(addr) && baseOffset == base.getOffset()) {
				return lastBaseIndex;
			}
		}

		int search = Arrays.binarySearch(sortedBaseStartAddrs, addr);
		if (search < 0) {
			search = -search - 2;
		}
		if (search >= 0) {
			Address base = sortedBaseStartAddrs[search];
			if (base.hasSameAddressSpace(addr) && baseOffset == base.getOffset()) {
				int index = addrToIndexMap.get(base);
				lastBaseIndex = index;
				return index;
			}
		}
		checkAddressSpace(addr.getAddressSpace());
		int index = baseAddrs.length;

		// Create new base without modifying database
		Address[] newBaseAddrs = new Address[baseAddrs.length + 1];
		System.arraycopy(baseAddrs, 0, newBaseAddrs, 0, baseAddrs.length);
		newBaseAddrs[index] = addr.getAddressSpace().getAddressInThisSpaceOnly(baseOffset);
		baseAddrs = newBaseAddrs;

		init(); // re-sorts baseAddrs
		lastBaseIndex = index;
		return lastBaseIndex;
	}
Comparator used to identify if an addr occurs before or after the 
start of a key range.
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/AddressMapImpl.java