@param array $base
@param Diff $diff

@return array
182173
private function patchMapOrList( array $base, Diff $diff ): array {
		if ( $diff->looksAssociative() ) {
			return $this->patch( $base, $diff );
		}

		return $this->listPatcher->patch( $base, $diff );
	}
1281269
public function getDiffs() {
    $diffs = array();
    foreach ($this->diffs as $diff) {
      if ($diff[1] !== self::OLD) {
        $diffs[] = $diff;
      } 
    }
    return $diffs;
  }
761382
private function applyOperation( array &$base, $key, DiffOp $diffOp ) {
		if ( $diffOp instanceof DiffOpAdd ) {
			$this->applyDiffOpAdd( $base, $key, $diffOp );
		}
		elseif ( $diffOp instanceof DiffOpChange ) {
			$this->applyDiffOpChange( $base, $key, $diffOp );
		}
		elseif ( $diffOp instanceof DiffOpRemove ) {
			$this->applyDiffOpRemove( $base, $key, $diffOp );
		}
		elseif ( $diffOp instanceof Diff ) {
			$this->applyDiff( $base, $key, $diffOp );
		}
		else {
			$this->handleError( 'Unknown diff operation cannot be applied to map element' );
		}
	}
300146
protected function array_compare_recursive(Array &$base = null, Array $acquisition) : Array {
		if(isset($base)){
			$this->resolveDatatypeConflicts($base, $acquisition);
		}

		foreach ($acquisition as $key => $aValue) {
			// create new key in $base, if it is empty
			if (!isset($base[$key])) {
				$base[$key] = null;
			}

			// overwrite the value in the base array
			if (
				is_array($aValue) &&
				!(isset($aValue['max']) && isset($base[$key]['max']))
			) {
				$aValue = $this->array_compare_recursive($base[$key], $aValue);
			}

			// compare max if exists
			if (isset($aValue['max']) && isset($base[$key]['max'])) {
				$oldBaseMax = $base[$key]['max'];
				$bMax = $base[$key]['max']['measure'] ?? $base[$key]['max']['value'];
				$aMax = $aValue['max']['measure'] ?? $aValue['max']['value'];
				if (($bMax <=> $aMax) < 0) {
					$base[$key]['max'] = $aValue['max'];
				}
			} else {
				if ($key === 'distinct') {
					$base[$key] = max($base[$key],$aValue);
				} else {
					$base[$key] = $aValue;
				}
				continue;
			}

			// compare optional minimums
			$bMin = $base[$key]['min']['measure'] ?? $base[$key]['min']['value'] ?? null;
			$aMin = $aValue['min']['measure'] ?? $aValue['min']['value'] ?? null;

			// if both min set
			if (isset($aMin, $bMin)) {
				if (($bMin <=> $aMin) > 0) {
					$base[$key]['min'] = $aValue['min'];
				}
				continue;
			}

			// if only acquisition min and no base min
			// if old base max < acquisition min,
			// then base min = old base max
			if(isset($aMin)){
				if (($bMax <=> $aMin) < 0) {
					$base[$key]['min'] = $oldBaseMax;
				} else {
					$base[$key]['min'] = $aValue['min'];
				}
				continue;
			}

			// if only $base min,
			// if acquisition max is less than base min,
			// then set acquisition max as new min
			if(isset($bMin)){
				if (($bMin <=> $aMax) > -1) {
					$base[$key]['min'] = $aValue['max'];
				}
				continue;
			}

			// if no min, then compare maxes to set min
			if($bMax !== $aMax){
				if($bMax < $aMax){
					$base[$key]['min'] = $oldBaseMax;
				} else {
					$base[$key]['min'] = $aValue['max'];
				}
			}
		}

		return $base;
	}
363398
private function mergeData(array $base, array $replacements)
    {
        return array_filter(array_merge($base, $replacements), function($value) {
            return $value !== null;
        });
    }
725625
public function getRates($base = null, $date = null) : array
    {
        $rates = $this->getRateModel($base, $date);

        return $rates->toArray();
    }
506882
private function applyDiffOpRemove( array &$base, $key, DiffOpRemove $diffOp ) {
		if ( !array_key_exists( $key, $base ) ) {
			$this->handleError( 'Cannot do a non-add operation with an element not present in a map' );
			return;
		}

		if ( !$this->valuesAreEqual( $base[$key], $diffOp->getOldValue() ) ) {
			$this->handleError( 'Tried removing a map value that mismatches the current value' );
			return;
		}

		unset( $base[$key] );
	}
886734
private function diff(array $a, array $b)
    {
        if (empty($a)) {
            $a = [];
        }
        if (empty($b)) {
            $b = [];
        }
        $keys = array_keys($a + $b);
        $result = [];

        foreach ($keys as $k) {
            if (empty($a[$k])) {
                $l = null;
            } else {
                $l = $a[$k];
            }
            if (empty($b[$k])) {
                $r = null;
            } else {
                $r = $b[$k];
            }
            if ($l != $r) {
                $result[] = [$k, $l, $r];
            }
        }

        return $result;
    }
339077
public function diffChangeLogFromSchemaDiff(SchemaDiff $schemaDiff, $output = null)
    {
        $output = $this->sanitizeOutputParameter($output);

        $output->started($this->em);

        foreach ($schemaDiff->newNamespaces as $newNamespace) {
            $output->createSchema($newNamespace);
        }

        foreach ($schemaDiff->orphanedForeignKeys as $orphanedForeignKey) {
            $output->dropForeignKey($orphanedForeignKey, $orphanedForeignKey->getLocalTable());
        }

        foreach ($schemaDiff->changedSequences as $sequence) {
            $output->alterSequence($sequence);
        }

        foreach ($schemaDiff->removedSequences as $sequence) {
            $output->dropSequence($sequence);
        }

        foreach ($schemaDiff->newSequences as $sequence) {
            $output->createSequence($sequence);
        }

        foreach ($schemaDiff->newTables as $table) {
            $output->createTable($table);
            
            foreach ($table->getForeignKeys() as $foreignKey) {
                $output->createForeignKey($foreignKey, $table);
            }
        }

        foreach ($schemaDiff->removedTables as $table) {
            $output->dropTable($table);
        }

        foreach ($schemaDiff->changedTables as $tableDiff) {
            $output->alterTable($tableDiff);
        }

        $output->terminated();

        return $output->getResult();
    }
1359107
public static function diffAssocRecursive($array1, $array2)
    {
        $difference = array();

        foreach ($array1 as $key => $value) {
            if (is_array($value)) {
                if (!isset($array2[$key]) || !is_array($array2[$key])) {
                    $difference[$key] = $value;
                } else {
                    $new_diff = self::diffAssocRecursive($value, $array2[$key]);
                    if (!empty($new_diff)) {
                        $difference[$key] = $new_diff;
                    }
                }
            } elseif (!array_key_exists($key, $array2) || $array2[$key] !== $value) {
                $difference[$key] = $value;
            }
        }

        return $difference;
    }
331014
private function buildGroups($diff, $offset = 2) {
        $groups = [];

        for ($i = 0; $i < count($diff); $i++) {
            if (!$diff[$i] instanceof UnmodifiedEntry) {
                $group = new DiffGroup();

                // Beginning offset
                for ($j = $i - 1; $j >= $i - $offset && $j >= 0; $j--) {
                    if ($diff[$j] instanceof UnmodifiedEntry) {
                        $group->addEntry($diff[$j], true);
                    }
                }

                for (; $i < count($diff) && !$diff[$i] instanceof UnmodifiedEntry; $i++) {
                    $group->addEntry($diff[$i]);
                }

                // Ending offset
                for ($j = $i; $j <= $i + $offset - 1 && $j < count($diff); $j++) {
                    if ($diff[$j] instanceof UnmodifiedEntry) {
                        $group->addEntry($diff[$j]);
                    }
                }

                $groups[] = $group;
            }
        }

        return $groups;
    }
242191
function diffKeys($arr) {
        if($arr instanceof self) {
            $arr = $arr->all();
        }
        
        return (new self(\array_diff_key($this->data, $arr)));
    }
1255804
public function getModifyColumnDDL(ColumnDiff $columnDiff)
    {
        $ret = '';
        $changedProperties = $columnDiff->getChangedProperties();

        $fromColumn = $columnDiff->getFromColumn();
        $toColumn = clone $columnDiff->getToColumn();

        $fromTable = $fromColumn->getTable();
        $table = $toColumn->getTable();

        $colName = $this->quoteIdentifier($toColumn->getName());

        $pattern = "
ALTER TABLE %s ALTER COLUMN %s;
";

        if (isset($changedProperties['autoIncrement'])) {
            $tableName = $table->getName();
            $colPlainName = $toColumn->getName();
            $seqName = "{$tableName}_{$colPlainName}_seq";

            if ($toColumn->isAutoIncrement() && $table && $table->getIdMethodParameters() == null) {

                $defaultValue = "nextval('$seqName'::regclass)";
                $toColumn->setDefaultValue($defaultValue);
                $changedProperties['defaultValueValue'] = [null, $defaultValue];

                //add sequence
                if (!$fromTable->getDatabase()->hasSequence($seqName)) {
                    $this->createOrDropSequences .= sprintf("
CREATE SEQUENCE %s;
",
                        $seqName
                    );
                    $fromTable->getDatabase()->addSequence($seqName);
                }
            }

            if (!$toColumn->isAutoIncrement() && $fromColumn->isAutoIncrement()) {
                $changedProperties['defaultValueValue'] = [$fromColumn->getDefaultValueString(), null];
                $toColumn->setDefaultValue(null);

                //remove sequence
                if ($fromTable->getDatabase()->hasSequence($seqName)) {
                    $this->createOrDropSequences .= sprintf("
DROP SEQUENCE %s CASCADE;
",
                        $seqName
                    );
                    $fromTable->getDatabase()->removeSequence($seqName);
                }
            }
        }

        if (isset($changedProperties['size']) || isset($changedProperties['type']) || isset($changedProperties['sqlType']) || isset($changedProperties['scale'])) {

            $sqlType = $toColumn->getDomain()->getSqlType();

            if ($this->hasSize($sqlType) && $toColumn->isDefaultSqlType($this)) {
                if ($this->isNumber($sqlType)) {
                    if ('NUMERIC' === strtoupper($sqlType)) {
                        $sqlType .= $toColumn->getSizeDefinition();
                    }
                } else {
                    $sqlType .= $toColumn->getSizeDefinition();
                }
            }

            if ($using = $this->getUsingCast($fromColumn, $toColumn)) {
                $sqlType .= $using;
            }
            $ret .= sprintf($pattern,
                $this->quoteIdentifier($table->getName()),
                $colName . ' TYPE ' . $sqlType
            );
        }

        if (isset($changedProperties['defaultValueValue'])) {
            $property = $changedProperties['defaultValueValue'];
            if ($property[0] !== null && $property[1] === null) {
                $ret .= sprintf($pattern, $this->quoteIdentifier($table->getName()), $colName . ' DROP DEFAULT');
            } else {
                $ret .= sprintf($pattern, $this->quoteIdentifier($table->getName()), $colName . ' SET ' . $this->getColumnDefaultValueDDL($toColumn));
            }
        }

        if (isset($changedProperties['notNull'])) {
            $property = $changedProperties['notNull'];
            $notNull = ' DROP NOT NULL';
            if ($property[1]) {
                $notNull = ' SET NOT NULL';
            }
            $ret .= sprintf($pattern, $this->quoteIdentifier($table->getName()), $colName . $notNull);
        }

        return $ret;
    }
732752
public function getInsertDiff()
    {
        return array_udiff_assoc(
            $this->collection->toArray(),
            $this->snapshot,
            function($a, $b) { return $a === $b ? 0 : 1; }
        );
    }
369840
public function diff($start, $end, $level = 'MB')
    {
        $startPoint = $this->getPoint($start);
        $endPoint   = $this->getPoint($end);

        return [
            'time'   => $endPoint['time'] - $startPoint['time'],
            'memory' => ($endPoint['memory'] - $startPoint['memory']) / pow(1024, (int) array_search($level, $this->memoryLevel))
        ];
    }
552254
def GetBaseFiles(self, diff):
		
		files = {}
		for line in diff.splitlines(True):
			if line.startswith('Index:') or line.startswith('Property changes on:'):
				unused, filename = line.split(':', 1)
				# On Windows if a file has property changes its filename uses '\'
				# instead of '/'.
				filename = to_slash(filename.strip())
				files[filename] = self.GetBaseFile(filename)
		return files
242269
private function applyDiff( &$base, $key, Diff $diffOp ) {
		if ( $this->isAttemptToModifyNotExistingElement( $base, $key, $diffOp ) ) {
			$this->handleError( 'Cannot apply a diff with non-add operations to an element not present in a map' );
			return;
		}

		if ( !array_key_exists( $key, $base ) ) {
			$base[$key] = [];
		}

		$base[$key] = $this->patchMapOrList( $base[$key], $diffOp );
	}