<commit_before>/* Soot - a J*va Optimization Framework
 * Copyright (C) 1997-1999 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/*
 * Modified by the Sable Research Group and others 1997-1999.  
 * See the 'credits' file distributed with Soot for the complete list of
 * contributors.  (Soot is distributed at http://www.sable.mcgill.ca/soot)
 */

package soot.toolkits.scalar;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

/**
 * Reference implementation for a FlowSet. Items are stored in an Array.
 */
public class ArraySparseSet<T> extends AbstractFlowSet<T> {
	protected static final int DEFAULT_SIZE = 8;

	protected int numElements;
	protected int maxElements;
	protected T[] elements;

	@SuppressWarnings("unchecked")
	public ArraySparseSet() {
		maxElements = DEFAULT_SIZE;
		elements = (T[]) new Object[DEFAULT_SIZE];
		numElements = 0;
	}

	private ArraySparseSet(ArraySparseSet<T> other) {
		numElements = other.numElements;
		maxElements = other.maxElements;
		elements = other.elements.clone();
	}

	/** Returns true if flowSet is the same type of flow set as this. */
	private boolean sameType(Object flowSet) {
		return (flowSet instanceof ArraySparseSet);
	}

	public ArraySparseSet<T> clone() {
		return new ArraySparseSet<T>(this);
	}

	public FlowSet<T> emptySet() {
		return new ArraySparseSet<T>();
	}

	public void clear() {
		numElements = 0;
	}

	public int size() {
		return numElements;
	}

	public boolean isEmpty() {
		return numElements == 0;
	}

	/** Returns a unbacked list of elements in this set. */
	public List<T> toList() {
        @SuppressWarnings("unchecked")
		T[] copiedElements = (T[]) new Object[numElements];
        System.arraycopy(elements, 0, copiedElements, 0, numElements);
        return Arrays.asList(copiedElements);
	}

	/*
	 * Expand array only when necessary, pointed out by <NAME> March
	 * 08, 2002
	 */
	public void add(T e) {
		/* Expand only if necessary! and removes one if too:) */
		// Add element
		if (!contains(e)) {
			// Expand array if necessary
			if (numElements == maxElements)<commit_msg>Refactored with java.util.BitSet<commit_after>/* Soot - a J*va Optimization Framework
 * Copyright (C) 1997-1999 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/*
 * Modified by the Sable Research Group and others 1997-1999.  
 * See the 'credits' file distributed with Soot for the complete list of
 * contributors.  (Soot is distributed at http://www.sable.mcgill.ca/soot)
 */

package soot.toolkits.scalar;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

/**
 * Reference implementation for a FlowSet. Items are stored in an Array.
 */
public class ArraySparseSet<T> extends AbstractFlowSet<T> {
	protected static final int DEFAULT_SIZE = 8;

	protected int numElements;
	protected int maxElements;
	protected T[] elements;

	@SuppressWarnings("unchecked")
	public ArraySparseSet() {
		maxElements = DEFAULT_SIZE;
		elements = (T[]) new Object[DEFAULT_SIZE];
		numElements = 0;
	}

	private ArraySparseSet(ArraySparseSet<T> other) {
		numElements = other.numElements;
		maxElements = other.maxElements;
		elements = other.elements.clone();
	}

	/** Returns true if flowSet is the same type of flow set as this. */
	private boolean sameType(Object flowSet) {
		return (flowSet instanceof ArraySparseSet);
	}

	public ArraySparseSet<T> clone() {
		return new ArraySparseSet<T>(this);
	}

	public FlowSet<T> emptySet() {
		return new ArraySparseSet<T>();
	}

	public void clear() {
		numElements = 0;
		Arrays.fill(elements, null);
	}

	public int size() {
		return numElements;
	}

	public boolean isEmpty() {
		return numElements == 0;
	}

	/** Returns a unbacked list of elements in this set. */
	public List<T> toList() {        
        return Arrays.asList(Arrays.copyOf(elements, numElements));
	}

	/*
	 * Expand array only when necessary, pointed out by <NAME>
	 * 08, 2002
	 */
	public void add(T e) {
		/* Expand only if necessary! and removes one if too:) */
		// Add element
		if (!contains(e)) {
			// Expand array if necessary
			if (numElements == maxElements)
{'fraction_non_alphanumeric': 0.09626436781609195, 'fraction_numerical': 0.015445402298850575, 'mean_word_length': 3.7761578044596913, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4431427', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1620, 'n_words': 640}