1 11 package org.eclipse.jdt.internal.core.index; 12 13 import org.eclipse.jdt.core.search.*; 14 import org.eclipse.jdt.internal.core.util.*; 15 import org.eclipse.jdt.internal.compiler.util.HashtableOfObject; 16 import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; 17 import org.eclipse.jdt.internal.compiler.util.SimpleSet; 18 19 public class MemoryIndex { 20 21 public int NUM_CHANGES = 100; 23 SimpleLookupTable docsToReferences; SimpleWordSet allWords; String lastDocumentName; 26 HashtableOfObject lastReferenceTable; 27 28 MemoryIndex() { 29 this.docsToReferences = new SimpleLookupTable(7); 30 this.allWords = new SimpleWordSet(7); 31 } 32 void addDocumentNames(String substring, SimpleSet results) { 33 Object [] paths = this.docsToReferences.keyTable; 35 Object [] referenceTables = this.docsToReferences.valueTable; 36 if (substring == null) { for (int i = 0, l = referenceTables.length; i < l; i++) 38 if (referenceTables[i] != null) 39 results.add(paths[i]); 40 } else { 41 for (int i = 0, l = referenceTables.length; i < l; i++) 42 if (referenceTables[i] != null && ((String ) paths[i]).startsWith(substring, 0)) 43 results.add(paths[i]); 44 } 45 } 46 void addIndexEntry(char[] category, char[] key, String documentName) { 47 HashtableOfObject referenceTable; 48 if (documentName.equals(this.lastDocumentName)) 49 referenceTable = this.lastReferenceTable; 50 else { 51 referenceTable = (HashtableOfObject) this.docsToReferences.get(documentName); 53 if (referenceTable == null) 54 this.docsToReferences.put(documentName, referenceTable = new HashtableOfObject(3)); 55 this.lastDocumentName = documentName; 56 this.lastReferenceTable = referenceTable; 57 } 58 59 SimpleWordSet existingWords = (SimpleWordSet) referenceTable.get(category); 60 if (existingWords == null) 61 referenceTable.put(category, existingWords = new SimpleWordSet(1)); 62 63 existingWords.add(this.allWords.add(key)); 64 } 65 HashtableOfObject addQueryResults(char[][] categories, char[] key, int matchRule, HashtableOfObject results) { 66 Object [] paths = this.docsToReferences.keyTable; 69 Object [] referenceTables = this.docsToReferences.valueTable; 70 if (matchRule == (SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE) && key != null) { 71 nextPath : for (int i = 0, l = referenceTables.length; i < l; i++) { 72 HashtableOfObject categoryToWords = (HashtableOfObject) referenceTables[i]; 73 if (categoryToWords != null) { 74 for (int j = 0, m = categories.length; j < m; j++) { 75 SimpleWordSet wordSet = (SimpleWordSet) categoryToWords.get(categories[j]); 76 if (wordSet != null && wordSet.includes(key)) { 77 if (results == null) 78 results = new HashtableOfObject(13); 79 EntryResult result = (EntryResult) results.get(key); 80 if (result == null) 81 results.put(key, result = new EntryResult(key, null)); 82 result.addDocumentName((String ) paths[i]); 83 continue nextPath; 84 } 85 } 86 } 87 } 88 } else { 89 for (int i = 0, l = referenceTables.length; i < l; i++) { 90 HashtableOfObject categoryToWords = (HashtableOfObject) referenceTables[i]; 91 if (categoryToWords != null) { 92 for (int j = 0, m = categories.length; j < m; j++) { 93 SimpleWordSet wordSet = (SimpleWordSet) categoryToWords.get(categories[j]); 94 if (wordSet != null) { 95 char[][] words = wordSet.words; 96 for (int k = 0, n = words.length; k < n; k++) { 97 char[] word = words[k]; 98 if (word != null && Index.isMatch(key, word, matchRule)) { 99 if (results == null) 100 results = new HashtableOfObject(13); 101 EntryResult result = (EntryResult) results.get(word); 102 if (result == null) 103 results.put(word, result = new EntryResult(word, null)); 104 result.addDocumentName((String ) paths[i]); 105 } 106 } 107 } 108 } 109 } 110 } 111 } 112 return results; 113 } 114 boolean hasChanged() { 115 return this.docsToReferences.elementSize > 0; 116 } 117 void remove(String documentName) { 118 if (documentName.equals(this.lastDocumentName)) { 119 this.lastDocumentName = null; 120 this.lastReferenceTable = null; 121 } 122 this.docsToReferences.put(documentName, null); 123 } 124 boolean shouldMerge() { 125 return this.docsToReferences.elementSize >= NUM_CHANGES; 126 } 127 } 128 | Popular Tags |