1 2 package SOFA.SOFAnode.Util; 3 4 10 public class IntVector { 11 public int data[]; 12 public int size; 13 public int used; 14 15 public int sz_initial = 16; 16 17 20 public IntVector() { data = null; size=0; used=0; }; 21 22 29 public IntVector(int iarr[], boolean docopy) { 30 if (docopy) { 31 data=new int[iarr.length]; 32 for (int i=0;i<iarr.length;i++) data[i]=iarr[i]; 33 } else { data=iarr; }; 34 size=used=iarr.length; 35 }; 36 37 38 43 public IntVector(IntVector copyfrom) { 44 data=new int[copyfrom.used]; 45 for (int i=0;i<copyfrom.used;i++) data[i]=copyfrom.data[i]; 46 size=used=copyfrom.used; 47 }; 48 49 59 public String dump() { 60 StringBuffer s = new StringBuffer (); 61 s.append("["); 62 for (int i=0;i<used;i++) { 63 s.append(data[i]); if (i+1<used) s.append(","); 64 }; 65 s.append("]"); 66 return s.toString(); 67 }; 68 69 78 public void sortedAddIntIfNExists(int i) { 79 int j=0,t; 80 81 while ((j<used) && (data[j]<i)) j++; 82 83 if (j==used) addInt(i); 84 else { 85 if (data[j]==i) return; 86 while (j<used) { 87 t=data[j]; data[j]=i; i=t; 88 j++; 89 }; 90 addInt(i); 91 }; 92 }; 93 94 108 public IntVector(int iarr[], int minValue) { 109 int i,n=0; 110 for (i=0;i<iarr.length;i++) if (iarr[i]>=minValue) n++; 111 size=n; data = new int[size]; 112 for (i=0;i<iarr.length;i++) if (iarr[i]>=minValue) data[used++]=i; 113 } 114 115 124 public int addInt(int i) { 125 checkSize(used+1); data[used++]=i; return used-1; 126 }; 127 128 public void checkSize(int requested) { 129 if (requested>size) { 130 if (size==0) size=sz_initial; else size*=2; 131 int newdata[]=new int[size]; 132 for (int i=0;i<used;i++) newdata[i]=data[i]; 133 data=newdata; 134 }; 135 }; 136 }; 137 138 139 | Popular Tags |