Subversion Repositories programming

Rev

Rev 16 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 16 Rev 17
Line 184... Line 184...
184
    private int nextProbe(int h, int i) {
184
    private int nextProbe(int h, int i) {
185
        
185
        
186
    int returnVal = 0; //set to zero to stop compiler error
186
    int returnVal = 0; //set to zero to stop compiler error
187
 
187
 
188
    switch( probeType ) {
188
    switch( probeType ) {
189
        case 0: { //linear probing
189
        case 0: //linear probing
190
            returnVal = (h + i)%entries.length;
190
            returnVal = (h + i)%entries.length;
191
            break;
191
            break;
192
        }
-
 
193
 
-
 
194
        case 1: { //Prime Probing ( p=3  )
192
        case 1: //Prime Probing ( p=3  )
195
            returnVal = (h + (i * 3 ))%entries.length; 
193
            returnVal = (h + (i * 3 ))%entries.length; 
196
            break;
194
            break;
197
        }
-
 
198
 
-
 
199
        case 2: { //Prime Probing ( p=5  )
195
        case 2: //Prime Probing ( p=5  )
200
            returnVal = (h + (i * 5 ))%entries.length;
196
            returnVal = (h + (i * 5 ))%entries.length;
201
            break;
197
            break;
202
        }
-
 
203
 
-
 
204
        case 3: {  //Prime Probing ( p=7  )
198
        case 3: //Prime Probing ( p=7  )
205
            returnVal = (h + (i * 7 ))%entries.length;
199
            returnVal = (h + (i * 7 ))%entries.length;
206
            break;
200
            break;
207
        }
-
 
208
 
-
 
209
        case 4: { //Prime Probing ( p=11 )
201
        case 4: //Prime Probing ( p=11 )
210
            returnVal = (h + (i * 11))%entries.length;
202
            returnVal = (h + (i * 11))%entries.length;
211
            break;
203
            break;
212
        }
-
 
213
 
-
 
214
        case 5: { //Quadratic Probing
204
        case 5: //Quadratic Probing
215
            returnVal = (h + (i * i ))%entries.length;
205
            returnVal = (h + (i * i ))%entries.length;
216
            break;
206
            break;
217
        }
-
 
218
 
-
 
219
        //I am aware that my implementation of Double Hashing (which follows) is
207
        //I am aware that my implementation of Double Hashing (which follows) is
220
        //wasteful in terms of computation time (we must create the array "step"
208
        //wasteful in terms of computation time (we must create the array "step"
221
        //each and every time this code is run.  I did it this way to abstract the
209
        //each and every time this code is run.  I did it this way to abstract the
222
        //method used to find the nextProbe() location from the put method.
210
        //method used to find the nextProbe() location from the put method.
223
        case 6: { //Double Hashing
211
        case 6: //Double Hashing
224
            int[] step = { 2,3,5,7,11 };
212
            int[] step = { 2,3,5,7,11 };
225
            int stepSize = step[h%4];
213
            int stepSize = step[h%4];
226
            returnVal = (h + (i * stepSize))%entries.length;
214
            returnVal = (h + (i * stepSize))%entries.length;
227
            break;
215
            break;
228
        }
-
 
229
    }
216
    }
230
    //return the final value
217
    //return the final value
231
    return returnVal;
218
    return returnVal;
232
    
219
    
233
    }
220
    }