1 11 package org.eclipse.jdt.internal.core.builder; 12 13 import org.eclipse.jdt.core.compiler.CharOperation; 14 15 public class QualifiedNameSet { 16 17 public char[][][] qualifiedNames; 19 public int elementSize; public int threshold; 21 22 public QualifiedNameSet(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.qualifiedNames = new char[extraRoom][][]; 29 } 30 31 public char[][] add(char[][] qualifiedName) { 32 int qLength = qualifiedName.length; 33 if (qLength == 0) return CharOperation.NO_CHAR_CHAR; 34 35 int length = qualifiedNames.length; 36 int index = CharOperation.hashCode(qualifiedName[qLength - 1]) % length; 37 char[][] current; 38 while ((current = qualifiedNames[index]) != null) { 39 if (CharOperation.equals(current, qualifiedName)) return current; 40 if (++index == length) index = 0; 41 } 42 qualifiedNames[index] = qualifiedName; 43 44 if (++elementSize > threshold) rehash(); 46 return qualifiedName; 47 } 48 49 private void rehash() { 50 QualifiedNameSet newSet = new QualifiedNameSet(elementSize * 2); char[][] current; 52 for (int i = qualifiedNames.length; --i >= 0;) 53 if ((current = qualifiedNames[i]) != null) 54 newSet.add(current); 55 56 this.qualifiedNames = newSet.qualifiedNames; 57 this.elementSize = newSet.elementSize; 58 this.threshold = newSet.threshold; 59 } 60 61 public String toString() { 62 String s = ""; char[][] qualifiedName; 64 for (int i = 0, l = qualifiedNames.length; i < l; i++) 65 if ((qualifiedName = qualifiedNames[i]) != null) 66 s += CharOperation.toString(qualifiedName) + "\n"; return s; 68 } 69 } 70 | Popular Tags |