private AddressSet getAddressFlow(TaskMonitor monitor, AddressSetView startAddresses,
			boolean forward) {

		if (monitor == null) {
			monitor = TaskMonitor.DUMMY; // create dummy monitor
		}

		// Create a new address set to hold the entire flow.
		AddressSet addressSet = new AddressSet();
		AddressSet coveredAddrs = new AddressSet();

		// If we don't have any addresses simply return.
		if (startAddresses == null || startAddresses.getNumAddresses() <= 0) {
			return addressSet;
		}

		// Iterate over all code units whose minimum address is contained within startAddresses
		Listing listing = program.getListing();
		CodeUnitIterator cuIter = listing.getCodeUnits(startAddresses, true);
		while (!monitor.isCancelled() && cuIter.hasNext()) {
			CodeUnit codeUnit = cuIter.next();
			coveredAddrs.addRange(codeUnit.getMinAddress(), codeUnit.getMaxAddress());
			getCodeUnitFlow(monitor, startAddresses, addressSet, codeUnit, forward);
		}

		// Make sure we did not omit any data elements
		AddressSet addrs = new AddressSet(startAddresses);
		addrs.delete(coveredAddrs);
		AddressIterator addrIter = addrs.getAddresses(true);
		while (!monitor.isCancelled() && addrIter.hasNext()) {
			Address addr = addrIter.next();
			if (addressSet.contains(addr))
				continue;
			Data data = listing.getDefinedDataContaining(addr);
			if (forward) {
				followCode(monitor, addressSet, data, addr);
			}
			else {
				followCodeBack(monitor, addressSet, data, addr);
			}
		}

		if (monitor.isCancelled()) {
			return new AddressSet();  // don't return a partial result
		}
		return addressSet;

	}
getAddressFlow follows the program's code flow and creates an address
set for the flow from the addresses that are provided when flowing in the forward direction
or creates an address set for the flows to the addresses in the address set if flowing
in the backward direction.
@param monitor a cancellable task monitor, may be null
@param startAddresses the initial addresses that should be flowed from or flowed to.
@param forward true to determine the flows "from" the startAddresses. false (backward) to 
determine flows "to" the startAddresses.
@return code unit flow represented by an address set as determined by the flow options.
An empty address set will be returned if cancelled.
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/block/FollowFlow.java