2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package gov.nasa.jpf.util;
21 * a simplistic IntSet implementation that uses an unsorted array to keep elements.
22 * Obviously this is O(N) and therefore not a good choice if the list grows,
23 * but if we know there are only a few elements then it isn't worth to
24 * do any sorting or fancy lookup - the JIT would beat algorithm.
26 * If the set is empty there is no memory allocated for the elements
28 public class UnsortedArrayIntSet extends ArrayIntSet {
30 static final int DEFAULT_CAPACITY = 4;
31 static final int GROWTH = 8;
33 public UnsortedArrayIntSet (){
37 public UnsortedArrayIntSet (int initialCapacity){
38 super(initialCapacity);
44 public boolean add (int v) {
47 elements = new int[DEFAULT_CAPACITY];
54 return false; // was already there
59 int[] newElements = new int[a.length + GROWTH];
60 System.arraycopy(a, 0, newElements, 0, size);
61 elements = newElements;
70 public boolean remove(int v) {
74 for (int i=0; i<len; i++){
81 System.arraycopy(a, i, a, i-1, len-i);
91 return false; // wasn't there
95 public boolean contains(int v) {
99 for (int i=0; i<len; i++){