1 package net.sf.saxon.event; 2 3 13 14 public class HTMLTagHashSet { 15 16 String [] strings; 17 int size; 18 19 public HTMLTagHashSet(int size) { 20 strings = new String [size]; 21 this.size = size; 22 } 23 24 public void add(String s) { 25 int hash = (hashCode(s) & 0x7fffffff) % size; 26 while(true) { 27 if (strings[hash]==null) { 28 strings[hash] = s; 29 return; 30 } 31 if (strings[hash].equalsIgnoreCase(s)) { 32 return; 33 } 34 hash = (hash + 1) % size; 35 } 36 } 37 38 public boolean contains(String s) { 39 int hash = (hashCode(s) & 0x7fffffff) % size; 40 while(true) { 41 if (strings[hash]==null) { 42 return false; 43 } 44 if (strings[hash].equalsIgnoreCase(s)) { 45 return true; 46 } 47 hash = (hash + 1) % size; 48 } 49 } 50 51 private int hashCode(String s) { 52 int hash = 0; 55 int limit = s.length(); 56 if (limit>24) limit = 24; 57 for (int i=0; i<limit; i++) { 58 hash = (hash<<1) + (s.charAt(i) & 0xdf); 59 } 60 return hash; 61 } 62 } 63 64 | Popular Tags |