private void MaybeDoFreezing(WrappedInt x, WrappedInt y) { if (IsGas(x) && IsGas(y)) { if (candidatePivot == x) { Freeze(x); } else { Freeze(y); } } }
public int Compare(WrappedInt x, WrappedInt y) { ++NumComparisons; MaybeDoFreezing(x, y); if (IsGas(x)) { candidatePivot = x; } else if (IsGas(y)) { candidatePivot = y; } return x.Value - y.Value; }
public int Compare(WrappedInt x, WrappedInt y) { ++NumComparisons; if (x.Value == y.Value) { return 0; } if (dag.ExistsDirectedPath(x.Value, y.Value)) { return -1; } if (dag.ExistsDirectedPath(y.Value, x.Value)) { return 1; } if (dag.CountDescendants(x.Value) < dag.CountDescendants(y.Value)) { dag.AddEdge(y.Value, x.Value); return 1; } dag.AddEdge(x.Value, y.Value); return -1; }
private bool IsGas(WrappedInt wi) { return wi.Value == gas; }
private void Freeze(WrappedInt wi) { wi.Value = numSolid; ++numSolid; }