<commit_before>/*
 * It is all about percolation =)
 */
//import WeightedQuickUnionUF;

public class Percolation {
    private WeightedQuickUnionUF wqfItems;
    private boolean[] wqfItemStatus;
    private int iEleNumTotal;
    private int iN;

    public Percolation(int N) { // create N-by-N grid, with all sites blocked
	int i;
	iEleNumTotal = N * N + 2;
	iN = N;

	wqfItems = new WeightedQuickUnionUF(iEleNumTotal);
	wqfItemStatus = new boolean[iEleNumTotal];
	for (i = 0; i < iEleNumTotal; i++) {
	    wqfItemStatus[i] = false;
	}
	wqfItemStatus[iEleNumTotal - 2] = true;
	wqfItemStatus[iEleNumTotal - 1] = true;

    }

    public void open(int i, int j) { // open site (row i, column j) if it is not
				     // already
	int iElementId;
	if (i < 1 || i > iN)
	    throw new IndexOutOfBoundsException("row index i out of bounds");
	if (j < 1 || j > iN)
	    throw new IndexOutOfBoundsException("col index i out of bounds");

	i -= 1;
	j -= 1;
	iElementId = i * iN + j;

	if (wqfItemStatus[iElementId]) {
	    return;
	}

	// /\
	// ||
	if (i > 0) {
	    if (wqfItemStatus[(i - 1) * iN + j]) {
		wqfItems.union((i - 1) * iN + j, iElementId);
	    }
	} else {
	    wqfItems.union(iEleNumTotal - 2, iElementId);
	}

	// ||
	// \/
	if (i < iN - 1) {
	    if (wqfItemStatus[(i + 1) * iN + j]) {
		wqfItems.union((i + 1) * iN + j, iElementId);
	    }

	} else {
	    wqfItems.union(iEleNumTotal - 1, iElementId);
	}

	// <--
	if (j > 0) {
	    if (wqfItemStatus[i * iN + j - 1]) {
		wqfItems.union(i * iN + j - 1, iElementId);
	    }
	}
	// -->
	if (j < iN - 1) {
	    if (wqfItemStatus[i * iN + j + 1]) {
		wqfItems.union(i * iN + j + 1, iElementId);
	    }
	}
	wqfItemStatus[iElementId] = true;
	return;

    }

    public boolean isOpen(int i, int j) { // is site (row i, column j) open?
	if (i < 1 || i > iN)
	    throw new IndexOutOfBoundsException("row index i out of bounds");
	if (j < 1 || j > iN)
	    throw new IndexOutOfBoundsException("col index i out of bounds");

	return wqfItemStatus[(i - 1) * iN + j - 1];
    }

    public boolean isFull(int i, int j) { // is site (row i, column j) full?
	if (i < 1 || i > iN)
	    throw new IndexOutOfBoundsException("row index i out of bounds");
	if (j < 1 || j > iN)
	    throw new IndexOutOfBoundsException("col index i out of bounds");
	return wqfItems.connected(iEleNumTotal - 2, (i - 1) * iN + j - 1);
    }
<commit_msg>Weak 1 done =)<commit_after>/*
 * It is all about percolation =)
 */
//import WeightedQuickUnionUF;

public class Percolation {
    private WeightedQuickUnionUF wqfItems;
    private WeightedQuickUnionUF wqfItemsNoBottom;
    private boolean[] wqfItemStatus;
    private int iEleNumTotal;
    private int iN;

    public Percolation(int N) { // create N-by-N grid, with all sites blocked
	int i;
	iEleNumTotal = N * N + 2;
	iN = N;

	wqfItems = new WeightedQuickUnionUF(iEleNumTotal);
	wqfItemsNoBottom = new WeightedQuickUnionUF(iEleNumTotal - 1);
	wqfItemStatus = new boolean[iEleNumTotal];
	for (i = 0; i < iEleNumTotal; i++) {
	    wqfItemStatus[i] = false;
	}
	wqfItemStatus[iEleNumTotal - 2] = true;
	wqfItemStatus[iEleNumTotal - 1] = true;
    }

    public void open(int i, int j) { // open site (row i, column j) if it is not
				     // already
	int iElementId;
	if (i < 1 || i > iN)
	    throw new IndexOutOfBoundsException("row index i out of bounds");
	if (j < 1 || j > iN)
	    throw new IndexOutOfBoundsException("col index i out of bounds");

	i -= 1;
	j -= 1;
	iElementId = i * iN + j;

	if (wqfItemStatus[iElementId]) {
	    return;
	}

	// /\
	// ||
	if (i > 0) {
	    if (wqfItemStatus[(i - 1) * iN + j]) {
		wqfItems.union((i - 1) * iN + j, iElementId);
		wqfItemsNoBottom.union((i - 1) * iN + j, iElementId);
	    }
	} else {
	    wqfItems.union(iEleNumTotal - 2, iElementId);
	    wqfItemsNoBottom.union(iEleNumTotal - 2, iElementId);
	}

	// ||
	// \/
	if (i < iN - 1) {
	    if (wqfItemStatus[(i + 1) * iN + j]) {
		wqfItems.union((i + 1) * iN + j, iElementId);
		wqfItemsNoBottom.union((i + 1) * iN + j, iElementId);
	    }

	} else {
	    wqfItems.union(iEleNumTotal - 1, iElementId);
	}

	// <--
	if (j > 0) {
	    if (wqfItemStatus[i * iN + j - 1]) {
		wqfItems.union(i * iN + j - 1, iElementId);
		wqfItemsNoBottom.union(i * iN + j - 1, iElementId);
	    }
	}
	// -->
	if (j < iN - 1) {
	    if (wqfItemStatus[i * iN + j + 1]) {
		wqfItems.union(i * iN + j + 1, iElementId);
		wqfItemsNoBottom.union(i * iN + j + 1, iElementId);
	    }
	}
	wqfItemStatus[iElementId] = true;
	return;

    }

    public boolean isOpen(int i, int j) { // is site (row i, column j) open?
	if (i < 1 || i > iN)
	    throw new IndexOutOfBoundsException("row index i out of bounds");
	if (j < 1 || j > iN)
	    throw new IndexOutOfBoundsException("col index i out of bounds");

	return wqfItemStatus[(i - 1) * iN + j - 1];
    }

    public boolean isFull(int i, int j) { // is site (row i, column j) full?
	if (i < 1 || i > iN)
	    throw new IndexOutOfBoundsException("row index i out of bounds");
	if (j < 1 || j > iN)
	    throw new IndexOutOfBoundsException("col index i out of bounds");
	return wqfItemsNoBottom.connected(iEleNumTotal - 2, (i - 1) * iN + j - 1);
    }

{'fraction_non_alphanumeric': 0.14606741573033707, 'fraction_numerical': 0.01336691204959318, 'mean_word_length': 2.607966457023061, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1341557', 'n_tokens_mistral': 2212, 'n_tokens_neox': 2063, 'n_words': 581}