1 11 package org.eclipse.jdt.internal.core.builder; 12 13 import org.eclipse.jdt.core.compiler.CharOperation; 14 15 public final class NameSet { 16 17 public char[][] names; 19 public int elementSize; public int threshold; 21 22 public NameSet(int size) { 23 this.elementSize = 0; 24 this.threshold = size; int extraRoom = (int) (size * 1.5f); 26 if (this.threshold == extraRoom) 27 extraRoom++; 28 this.names = new char[extraRoom][]; 29 } 30 31 public char[] add(char[] name) { 32 int length = names.length; 33 int index = CharOperation.hashCode(name) % length; 34 char[] current; 35 while ((current = names[index]) != null) { 36 if (CharOperation.equals(current, name)) return current; 37 if (++index == length) index = 0; 38 } 39 names[index] = name; 40 41 if (++elementSize > threshold) rehash(); 43 return name; 44 } 45 46 private void rehash() { 47 NameSet newSet = new NameSet(elementSize * 2); char[] current; 49 for (int i = names.length; --i >= 0;) 50 if ((current = names[i]) != null) 51 newSet.add(current); 52 53 this.names = newSet.names; 54 this.elementSize = newSet.elementSize; 55 this.threshold = newSet.threshold; 56 } 57 58 public String toString() { 59 String s = ""; char[] name; 61 for (int i = 0, l = names.length; i < l; i++) 62 if ((name = names[i]) != null) 63 s += new String (name) + "\n"; return s; 65 } 66 } 67 | Popular Tags |