From: bdemsky Date: Wed, 21 Oct 2009 00:02:57 +0000 (+0000) Subject: changes X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6f01142a42594eece255e45ef0f6b797e1983a94;p=IRC.git changes --- diff --git a/Robust/src/Benchmarks/SingleTM/Genome/ByteString.java b/Robust/src/Benchmarks/SingleTM/Genome/ByteString.java new file mode 100644 index 00000000..20f6c468 --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Genome/ByteString.java @@ -0,0 +1,171 @@ +public class ByteString { + byte value[]; + int count; + int offset; + private int cachedHashcode; + + private ByteString() { + } + + public ByteString(byte str[]) { + this.value=str; + this.count=str.length; + this.offset=0; + } + + public boolean endsWith(String suffix) { + return regionMatches(count - suffix.count, suffix, 0, suffix.count); + } + + + public ByteString substring(int beginIndex) { + return substring(beginIndex, this.count); + } + + public ByteString subString(int beginIndex, int endIndex) { + return substring(beginIndex, endIndex); + } + + public ByteString substring(int beginIndex, int endIndex) { + ByteString str=new ByteString(); + if (beginIndex>this.count||endIndex>this.count||beginIndex>endIndex) { + // FIXME + System.printString("Index error: "+beginIndex+" "+endIndex+" "+count+"\n"+this); + } + str.value=this.value; + str.count=endIndex-beginIndex; + str.offset=this.offset+beginIndex; + return str; + } + + public ByteString subString(int beginIndex) { + return this.subString(beginIndex, this.count); + } + + public int lastindexOf(int ch) { + return this.lastindexOf(ch, count - 1); + } + + public static ByteString concat2(ByteString s1, ByteString s2) { + if (s1==null) + return "null".concat(s2); + else + return s1.concat(s2); + } + + public ByteString concat(ByteString str) { + ByteString newstr=new ByteString(); + newstr.count=this.count+str.count; + byte charstr[]=new byte[newstr.count]; + newstr.value=charstr; + newstr.offset=0; + for(int i=0; i0; i--) + if (this.byteAt(i)==ch) + return i; + return -1; + } + + public int indexOf(int ch) { + return this.indexOf(ch, 0); + } + + public int indexOf(int ch, int fromIndex) { + for(int i=fromIndex; ifromIndex) + k=fromIndex; + for(; k>=0; k--) { + if (regionMatches(k, str, 0, str.count)) + return k; + } + return -1; + } + + public int lastIndexOf(ByteString str) { + return lastIndexOf(str, count-str.count); + } + + public boolean startsWith(ByteString str) { + return regionMatches(0, str, 0, str.count); + } + + public boolean startsWith(ByteString str, int toffset) { + return regionMatches(toffset, str, 0, str.count); + } + + public boolean regionMatches(int toffset, ByteString other, int ooffset, int len) { + if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count) + return false; + for(int i=0; i