convertDiff(diff) takes a `generic-diff` diff and turns it into an
an add/update/remove delta.

@param {Array} diff
@return {Array}
482243
function convertDiff (diff) {
  var converted = []
  var index = 0

  for (var i = 0; i < diff.length; i += 1) {
    var change = diff[i]

    if (!change.added && !change.removed) {
      index += change.items.length
      continue
    }

    var next = diff[i + 1]
    if (next && change.removed && next.added) {
      var changeLen = change.items.length
      var nextLen = next.items.length
      var len = Math.min(changeLen, nextLen)
      converted.push({
        items: next.items.slice(0, len),
        index: index,
        added: true,
        removed: true
      })

      index += len

      if (changeLen < nextLen) {
        converted.push({
          items: next.items.slice(len),
          index: index,
          added: true,
          removed: false
        })
        index += nextLen - len
      } else if (nextLen < changeLen) {
        converted.push({
          items: change.items.slice(len),
          index: index,
          added: false,
          removed: true
        })
      }

      i += 1
      continue
    }

    converted.push({
      items: change.items.slice(),
      index: index,
      added: change.added,
      removed: change.removed
    })

    if (change.added) {
      index += change.items.length
    }
  }

  return converted
}
1278140
function _VirtualDom_diffFacts(x, y, category) {
    var diff;

    // look for changes and removals
    for (var xKey in x) {
      if (xKey === "a1" || xKey === "a0" || xKey === "a3" || xKey === "a4") {
        var subDiff = _VirtualDom_diffFacts(x[xKey], y[xKey] || {}, xKey);
        if (subDiff) {
          diff = diff || {};
          diff[xKey] = subDiff;
        }
        continue;
      }

      // remove if not in the new facts
      if (!(xKey in y)) {
        diff = diff || {};
        diff[xKey] = !category
          ? typeof x[xKey] === "string"
            ? ""
            : null
          : category === "a1"
            ? ""
            : category === "a0" || category === "a3"
              ? undefined
              : { f: x[xKey].f, o: undefined };

        continue;
      }

      var xValue = x[xKey];
      var yValue = y[xKey];

      // reference equal, so don't worry about it
      if (
        (xValue === yValue && xKey !== "value" && xKey !== "checked") ||
        (category === "a0" && _VirtualDom_equalEvents(xValue, yValue))
      ) {
        continue;
      }

      diff = diff || {};
      diff[xKey] = yValue;
    }

    // add new stuff
    for (var yKey in y) {
      if (!(yKey in x)) {
        diff = diff || {};
        diff[yKey] = y[yKey];
      }
    }

    return diff;
  }
598127
function msDiff(t1, t2) {
  t1 = (t1[0] * 1e9 + t1[1]) / 1e6;
  t2 = (t2[0] * 1e9 + t2[1]) / 1e6;
  return Math.ceil((t1 - t2) * 100) / 100;
}
441814
def _make_diff(self, correct, given):
        """"""
        dmp = DMP()
        dmp.Diff_Timeout = 4
        text1, text2, array = dmp.diff_linesToChars(correct, given)
        diffs = dmp.diff_main(text1, text2)
        dmp.diff_cleanupSemantic(diffs)
        dmp.diff_charsToLines(diffs, array)
        return list(dmp_to_mdiff(diffs))
1316764
def join(cls, diffs: Iterable['DBDiff']) -> 'DBDiff':
        
        tracker = DBDiffTracker()
        for diff in diffs:
            diff.apply_to(tracker)
        return tracker.diff()
1075184
function prettifyDiffObj(diff) {
    const obj = {
        kind: undefined,
        path: undefined,
        expect: undefined,
        actual: undefined,
        index: undefined,
        item: undefined,
    };
    if (diff.kind) {
        switch (diff.kind) {
            case 'N':
                obj.kind = 'New';
                break;
            case 'D':
                obj.kind = 'Missing';
                break;
            case 'E':
                obj.kind = 'Changed';
                break;
            case 'A':
                obj.kind = 'Array Canged';
                break;
        }
    }
    if (diff.path) {
        let path = diff.path[0];
        for (let i = 1; i < diff.path.length; i++) {
            path += `/${diff.path[i]}`;
        }
        obj.path = path;
    }
    if (typeof diff.lhs !== 'undefined') {
        obj.expect = diff.lhs;
    }
    if (typeof diff.rhs !== 'undefined') {
        obj.actual = diff.rhs;
    }
    if (diff.index) {
        obj.index = diff.index;
    }
    if (diff.item) {
        obj.item = prettifyDiffObj(diff.item);
    }
    return obj;
}
157579
private function updateDiffTable(TableDiff $diff)
    {
        foreach (array_keys($this->paramMap) as $param) {
            if (!empty($diff->{$param})) {
                return $diff;
            }
        }

        return false;
    }
60094
function diffVersions(callback) {
        var prior = null;
        _.each(versions, function(version) {
          if (!prior) {
            version.diff = [ { value: '[NEW]', added: true } ];
          } else {
            version.diff = apos.diffPages(prior, version);
          }
          prior = version;
        });
        versions.reverse();
        return callback(null);
      }
1020824
function printDiff(diff) {
  diff.forEach(line => {
    if (line.added) {
      line.value.split('\n').forEach(l => l && console.log(chalk.green(' +++ ') + chalk.gray(l)));
    } else if (line.removed) {
      line.value.split('\n').forEach(l => l && console.log(chalk.red(' --- ') + chalk.gray(l)));
    }
  });
}
945877
public function newFromArray( array $diffOp ) {
		$this->assertHasKey( 'type', $diffOp );

		if ( $diffOp['type'] === 'add' ) {
			$this->assertHasKey( 'newvalue', $diffOp );
			return new DiffOpAdd( $this->arrayToObject( $diffOp['newvalue'] ) );
		}

		if ( $diffOp['type'] === 'remove' ) {
			$this->assertHasKey( 'oldvalue', $diffOp );
			return new DiffOpRemove( $this->arrayToObject( $diffOp['oldvalue'] ) );
		}

		if ( $diffOp['type'] === 'change' ) {
			$this->assertHasKey( 'newvalue', $diffOp );
			$this->assertHasKey( 'oldvalue', $diffOp );
			return new DiffOpChange(
				$this->arrayToObject( $diffOp['oldvalue'] ),
				$this->arrayToObject( $diffOp['newvalue'] ) );
		}

		if ( $diffOp['type'] === 'diff' ) {
			$this->assertHasKey( 'operations', $diffOp );
			$this->assertHasKey( 'isassoc', $diffOp );

			$operations = [];

			foreach ( $diffOp['operations'] as $key => $operation ) {
				$operations[$key] = $this->newFromArray( $operation );
			}

			return new Diff( $operations, $diffOp['isassoc'] );
		}

		throw new InvalidArgumentException( 'Invalid array provided. Unknown type' );
	}
406172
def checkdiff(a,b,sp=True):
  ''
  if sp: a=splitpreserve(a); b=splitpreserve(b)
  res=applydiff(a,rediff(a,b))
  if sp: res=''.join(res)
  return res
103133
function diffClamp(value, min, max) {
  if (value > max) {
    return { value: max, diff: value - max };
  } else if (value < min) {
    return { value: min, diff: value - min };
  }
  return { value, diff: 0 };
}
1163634
function diff(orig, dest, options) {
        var result, key, obj, objEx, origObj, origObjEx, i, t;
        orig = listToObject(orig, options.key);
        dest = listToObject(dest, options.key);
        result = { added: [], removed: [], modified: [], unchanged: [] };
        for (key in dest.valids) {
            if (dest.valids.hasOwnProperty(key)) {
                obj = dest.valids[key];
                origObj = orig.valids[key];
                if (origObj === undefined) {
                    result.added.push(obj);
                } else {
                    // keep and exclude
                    keep(origObj, obj, options);
                    objEx = exclude(obj, options.exclude);
                    origObjEx = exclude(origObj, options.exclude);
                    // compare
                    if (deepEqual(objEx, origObjEx)) {
                        result.unchanged.push(obj);
                    } else {
                        result.modified.push(obj);
                    }
                    delete orig.valids[key];
                }
            }
        }
        for (key in orig.valids) {
            if (orig.valids.hasOwnProperty(key)) {
                result.removed.push(orig.valids[key]);
            }
        }
        // discarded object (without a key)
        if (orig.discarded.length) {
            result.discardedOrig = orig.discarded;
        }
        if (dest.discarded.length) {
            result.discardedDest = dest.discarded;
        }
        // for (i = 0; i < orig.discarded.length; i =+ 1) {
        //     t = orig.discarded[i];
        // }

        return result;
    }
294833
function equalDiff(a, b, diff) {
  diff.a = {
    line: a.line,
    column: a.column
  };
  diff.b = {
    line: b.line,
    column: b.column
  };
  return false;
}
1361131
protected function normalizeRequestDiff($diff) {
		if (count($diff) === 1) {
			reset($diff);
			return key($diff);
		}
		
		return array_keys($diff);
	}
567567
function diffDataProps(props, oldProps) {
  if (oldProps === null) {
    return 'oldProps is null, initial diff';
  }

  // Support optional app defined comparison of data
  const {dataComparator} = props;
  if (dataComparator) {
    if (!dataComparator(props.data, oldProps.data)) {
      return 'Data comparator detected a change';
    }
    // Otherwise, do a shallow equal on props
  } else if (props.data !== oldProps.data) {
    return 'A new data container was supplied';
  }

  return null;
}
663067
function diffFile(existing, proposed, options) {
  let { ensureContents, exists, readChunk } = utils;
  let opts = options || {};

  let contentsA = existing.contents;
  let contentsB = proposed.contents;

  if (!contentsA && exists(existing)) {
    contentsA = readChunk(existing.path, 0, 4 + 4096);
  }

  if (!contentsB && exists(proposed)) {
    contentsB = readChunk(proposed.path, 0, 4 + 4096);
  }

  if ((contentsA && isBuffer(contentsA)) || (contentsB && isBuffer(contentsB))) {
    return diffBinary(existing, proposed);
  }

  ensureContents(existing);
  ensureContents(proposed);
  if (opts.diffText === true) {
    return diffText(existing.contents.toString(), proposed.contents.toString(), opts);
  }
  return diffChars(existing.contents.toString(), proposed.contents.toString(), opts);
}