private int getBaseAddressIndex(Address addr, boolean normalize, int indexOperation) {

		long normalizedOffset = normalize ? getNormalizedOffset(addr) : addr.getOffset();
		long normalizedBaseOffset = normalizedOffset & BASE_MASK;

		AddressSpace space = addr.getAddressSpace();
		Address tBase = space.getAddressInThisSpaceOnly(normalizedBaseOffset);
		if (tBase.equals(lastBaseAddress)) {
			return lastIndex;
		}
		Integer tIndex = addrToIndexMap.get(tBase);
		if (tIndex != null) {
			lastBaseAddress = tBase;
			lastIndex = tIndex;
			return tIndex;
		}
		else if (indexOperation == INDEX_MATCH) {
			return Integer.MIN_VALUE;
		}

		int search = normalize
				? Arrays.binarySearch(sortedBaseStartAddrs, addr, normalizingAddressComparator)
				: Arrays.binarySearch(sortedBaseStartAddrs, addr);

		if (search < 0) {
			search = -search - 2;
		}
		if (search >= 0) {
			// Check for match
			Address base = sortedBaseStartAddrs[search];
			if (base.hasSameAddressSpace(addr) && normalizedBaseOffset == base.getOffset()) {
				int index = addrToIndexMap.get(base);
				return index;
			}
		}
		if (indexOperation == INDEX_MATCH_OR_PREVIOUS) {
			if (search >= 0) {
				Address base = sortedBaseStartAddrs[search];
				int index = addrToIndexMap.get(base);
				return -index - 1;
			}
		}
		if (indexOperation == INDEX_MATCH_OR_NEXT) {
			int nextIndex = search + 1;
			if (nextIndex < sortedBaseStartAddrs.length) {
				Address base = sortedBaseStartAddrs[nextIndex];
				int index = addrToIndexMap.get(base);
				return -index - 1;
			}
		}
		if (indexOperation != INDEX_CREATE) {
			// existing base address entry not found - can not create
			return Integer.MIN_VALUE;
		}

		// A new address map entry is required
		checkAddressSpace(addr.getAddressSpace());
		int index = baseAddrs.length;
		if (readOnly) {
			// 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(normalizedBaseOffset);
			baseAddrs = newBaseAddrs;
		}
		else {
			baseAddrs = adapter.addBaseAddress(addr, normalizedBaseOffset);
			if (baseAddrs.length == 101) {
				// TODO: Added to identify rogue Analyzers which cause too many segments to be created
				// Leaving out stack trace because many object files really do have this many segments
				Msg.warn(this, "More than 100 address segments have been created!", null);
			}
		}
		addrToIndexMap.put(baseAddrs[index], index);
		init(false); // re-sorts baseAddrs
		return index;
	}
Get base address index
@param addr address
@param normalize if true image base offset will be applied to addr
@param indexOperation see INDEX_CREATE, INDEX_MATCH, INDEX_MATCH_OR_NEXT or INDEX_MATCH_OR_PREVIOUS
@return base address index or Integer.MIN_VALUE if index not found and create is false.  A negative 
value other than Integer.MIN_VALUE indicates a NEXT or PREVIOUS base index = -(return_value)-1.
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/map/AddressMapDB.java