inlined methods to get prefetch benefits from the benchmark
[IRC.git] / Robust / src / Benchmarks / Distributed / SpamFilter / GString.java
1 public class GString {
2   char value[];
3   int count;
4   int offset;
5
6   public GString() {
7   }
8
9   public GString(char c) {
10     char[] str = global new char[1];
11     str[0] = c;
12     GString(str);
13   }
14
15   public GString(String str) {
16     value = global new char[str.count];
17     for(int i =0; i< str.count;i++) {
18       value[i] = str.value[i+str.offset];
19     }
20     count = str.count;
21     offset = 0;
22   }
23
24   public GString(GString gstr) {
25     this.value = gstr.value;
26     this.count = gstr.count;
27     this.offset = gstr.offset;
28   }
29
30   /*
31   public GString(StringBuffer gsb) {
32     value = global new char[gsb.length()];
33     count = gsb.length();
34     offset = 0;
35     for (int i = 0; i < count; i++) 
36       value[i] = gsb.value[i];
37   }
38   */
39
40   public GString(char str[]) {
41     char charstr[]=new char[str.length];
42     for(int i=0; i<str.length; i++)
43       charstr[i]=str[i];
44     this.value=charstr;
45     this.count=str.length;
46     this.offset=0;
47   }
48
49   public static char[] toLocalCharArray(GString str) {
50     char[] c;
51     int length;
52
53     length = str.length();
54
55     c = new char[length];
56
57     for (int i = 0; i < length; i++) {
58       c[i] = str.value[i+str.offset];
59     }
60     return c;
61   }
62
63   public String toLocalString() {
64     return new String(toLocalCharArray(this));
65   }
66
67   public int length() {
68     return count;
69   }
70
71   public int indexOf(int ch, int fromIndex) {
72     for (int i = fromIndex; i < count; i++)
73       if (this.charAt(i) == ch) 
74         return i;
75     return -1;
76   }
77
78   public int lastindexOf(int ch) {
79     return this.lastindexOf(ch, count - 1);
80   }
81
82   public int lastindexOf(int ch, int fromIndex) {
83     for (int i = fromIndex; i > 0; i--) 
84       if (this.charAt(i) == ch) 
85         return i;
86     return -1;
87   }
88
89   public char charAt(int i) {
90     return value[i+offset];
91   }
92
93   public int indexOf(String str) {
94     return this.indexOf(str, 0);
95   }
96
97   public int indexOf(String str, int fromIndex) {
98     if (fromIndex < 0) 
99       fromIndex = 0;
100     for (int i = fromIndex; i <= (count-str.count); i++)
101       if (regionMatches(i, str, 0, str.count)) 
102         return i;
103     return -1;
104   }     
105
106   public boolean regionMatches(int toffset, String other, int ooffset, int len) {
107     if (toffset < 0 || ooffset < 0 || (toffset+len) > count || (ooffset+len) > other.count)
108       return false;
109
110     for (int i = 0; i < len; i++) {
111       if (other.value[i+other.offset+ooffset] != this.value[i+this.offset+toffset])
112         return false;
113     }
114     return true;
115   }
116
117   public String subString(int beginIndex, int endIndex) {
118     return substring(beginIndex, endIndex);
119   }
120
121   public String substring(int beginIndex, int endIndex) {
122     String str;
123     str = global new String();
124     str.value = this.value;
125     str.count = endIndex-beginIndex;
126     str.offset = this.offset + beginIndex;
127     return str; 
128   }
129
130   public static String valueOf(Object o) {
131     if (o==null)
132       return "null";
133     else
134       return o.toString();
135   }
136
137   public String toLocalString() {
138     return new String(toLocalCharArray(this));
139   }
140
141   public static char[] toLocalCharArray(GString str) {
142     char[] c;
143     int length;
144     length = str.length();
145     c = new char[length];
146     for (int i = 0; i < length; i++) {
147       c[i] = str.value[i+str.offset];
148     }
149     return c;
150   }
151
152   public int hashCode() {
153     String s = this.toLocalString();
154     return s.hashCode();
155   }
156
157   public boolean equals(Object o) {
158     if(o == null)
159       return false;
160     if(!(o instanceof GString))
161       return false;
162     GString gs = (GString)o;
163     String s1 = gs.toLocalString();
164     String s2 = this.toLocalString();
165     if(s2.equals(s1))
166       return true;
167     return false;
168   }
169 }