Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

ArrayWrapper.java

00001 package gov.nasa.arc.ase.jpf.jvm;
00002 
00003 import gov.nasa.arc.ase.util.HashData;
00004 
00005 public class ArrayWrapper {
00006   private int[] data;
00007   private int hashcode;
00008 
00009   public ArrayWrapper(int[] d) {
00010     data = compressArray(d);
00011 
00012     HashData hd = new HashData();
00013     for(int i = 0; i < d.length; i++)
00014       hd.add(d[i]);
00015     
00016     hashcode = hd.getValue();
00017   }  
00018   private int [] compressArray (int [] d) {
00019     int pos = 0;
00020     int zeros = 0;
00021     int [] comp = new int[d.length];
00022     for (int i = 0; i < d.length; i++) {
00023       if (d[i] == 0) 
00024     zeros++;
00025       else {
00026     if (zeros > 0) {
00027       if (zeros == 1)
00028         comp[pos] = 0;
00029       else
00030         comp[pos] = -zeros;
00031       pos++;
00032       zeros = 0;
00033     }
00034     comp[pos] = d[i];
00035     pos++;
00036       }
00037     }
00038     int [] result = new int[pos];
00039     System.arraycopy(comp,0,result,0,result.length);
00040     return result;
00041   }  
00042   public boolean equals(Object o) {
00043     if(this == o) return true;
00044     if(o == null) return false;
00045 
00046     ArrayWrapper a = (ArrayWrapper)o;
00047     int[] d1 = data;
00048     int[] d2 = a.data;
00049     int l = d1.length;
00050 
00051     if(l != d2.length) return false;
00052 
00053     for(int idx = 0; idx < l; idx++)
00054       if(d1[idx] != d2[idx]) return false;
00055 
00056     return true;
00057   }  
00058   public int[] getData() {
00059     return data;
00060   }  
00061   public int hashCode() {
00062     return hashcode;
00063   }  
00064   public int size() {
00065     return data.length * 4;
00066   }  
00067   public String toString() {
00068     StringBuffer sb = new StringBuffer();
00069     int sz = data.length;
00070 
00071     sb.append("data[");
00072     sb.append(sz);
00073     sb.append("] = { ");
00074     for(int i = 0; i < sz; i++) {
00075       if(i != 0) sb.append(", ");
00076       sb.append(data[i]);
00077     }
00078     sb.append(" }");
00079 
00080     return sb.toString();
00081   }  
00082 }

Generated at Thu Feb 7 06:39:38 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001