1 package gov.nasa.jpf.jvm; 20 21 import gov.nasa.jpf.util.Md5Set; 22 import com.twmacinta.util.MD5; 23 24 28 public class Md5StateSet implements StateSet { 29 30 MD5 md5 = new MD5(); 31 Md5Set set = new Md5Set(); 32 33 byte[] buf = new byte[4]; 35 int lastStateId; 36 boolean isNewState; 37 38 public boolean isNewState (int stateId) { 39 if (lastStateId == stateId) { 40 return isNewState; 41 } else { 42 return false; } 44 } 45 46 public int size () { 47 return set.size(); 48 } 49 50 54 public int add (SystemState ss) { 55 int[] sd = ss.getStoringData(); 56 57 md5.Init(); 58 for (int i=0; i<sd.length; i++) { 59 int n = sd[i]; 60 61 buf[0] = (byte)n; 67 buf[1] = (byte)(n>>8); 68 buf[2] = (byte)(n>>16); 69 buf[3] = (byte)(n>>24); 70 md5.Update( buf, 0, 4); 71 } 73 byte[] hash = md5.Final(); 74 75 isNewState = set.add(hash); 76 lastStateId = set.getId(hash); 77 78 return lastStateId; 79 } 80 81 } 82 83 | Popular Tags |