(String inp, int alphabets)
| 49 | } |
| 50 | |
| 51 | public static int HashFunction(String inp, int alphabets) |
| 52 | { |
| 53 | int k=inp.length()-1; |
| 54 | |
| 55 | int res=0; |
| 56 | |
| 57 | for(int i=0;i<inp.length();i++) |
| 58 | { |
| 59 | int asc = inp.charAt(i); |
| 60 | |
| 61 | res = res + (asc*(int)Math.pow(alphabets,k)); |
| 62 | |
| 63 | k--; |
| 64 | } |
| 65 | |
| 66 | return res; |
| 67 | } |
| 68 | } |