View | Details | Raw Unified | Return to bug 289057 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/util/HashtableOfObject.java (-2 / +45 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 24-29 Link Here
24
	public int elementSize; // number of elements in the table
24
	public int elementSize; // number of elements in the table
25
	int threshold;
25
	int threshold;
26
26
27
	// used during putInOrder
28
	private int lastIndex = -1;
29
	private boolean foundEmpty = false;
30
27
	public HashtableOfObject() {
31
	public HashtableOfObject() {
28
		this(13);
32
		this(13);
29
	}
33
	}
Lines 39-44 Link Here
39
		this.valueTable = new Object[extraRoom];
43
		this.valueTable = new Object[extraRoom];
40
	}
44
	}
41
45
46
	public  HashtableOfObject(int size, int hashtablesize) {
47
		this.elementSize = 0;
48
		this.threshold = size; // size represents the expected number of elements
49
		this.keyTable = new char[hashtablesize][];
50
		this.valueTable = new Object[hashtablesize];
51
	}
52
	
42
	public void clear() {
53
	public void clear() {
43
		for (int i = this.keyTable.length; --i >= 0;) {
54
		for (int i = this.keyTable.length; --i >= 0;) {
44
			this.keyTable[i] = null;
55
			this.keyTable[i] = null;
Lines 111-118 Link Here
111
		if (++this.elementSize > this.threshold)
122
		if (++this.elementSize > this.threshold)
112
			rehash();
123
			rehash();
113
		return value;
124
		return value;
125
	}	
126
	/**
127
	 * This can be used while recreating the hashtable from 
128
	 * an hashtable contents that was persisted on a file. 
129
	 * This should be called in the same order of the other hashtable's 
130
	 * valuetable. It also assumes that the key used and length
131
	 * are same. This function just tries to recreate the similar hashtable
132
	 * by finding out the empty slots.
133
	 */
134
	public Object putInOrder(char[] key, Object value) {
135
		int length = this.keyTable.length, 
136
		index = CharOperation.hashCode(key) % length;
137
138
		if (index <= this.lastIndex) {
139
			index = this.lastIndex + 1;
140
		} else if (index != this.lastIndex + 1) {
141
			if (!this.foundEmpty) {
142
				// in the previous hash table, this index could have 
143
				// had conflicts such that it could have got reindexed
144
				// at the beginning of the hash table, where as the original
145
				// index would have been at the end of the hashtable.
146
				if (index+this.threshold-this.elementSize > length) {
147
					index = this.lastIndex+1;
148
				} else {
149
					this.foundEmpty = true;
150
				}
151
			}
152
		}
153
		this.keyTable[index] = key;
154
		this.valueTable[index] = value;
155
		this.lastIndex = index;
156
		++this.elementSize;
157
		return value;
114
	}
158
	}
115
116
	public Object removeKey(char[] key) {
159
	public Object removeKey(char[] key) {
117
		int length = this.keyTable.length,
160
		int length = this.keyTable.length,
118
			index = CharOperation.hashCode(key) % length;
161
			index = CharOperation.hashCode(key) % length;
(-)search/org/eclipse/jdt/internal/core/index/DiskIndex.java (-14 / +17 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 46-52 Link Here
46
private int streamEnd; // used when writing data from the streamBuffer to the file
46
private int streamEnd; // used when writing data from the streamBuffer to the file
47
char separator = Index.DEFAULT_SEPARATOR;
47
char separator = Index.DEFAULT_SEPARATOR;
48
48
49
public static final String SIGNATURE= "INDEX VERSION 1.126"; //$NON-NLS-1$
49
public static final String SIGNATURE= "INDEX VERSION 1.127"; //$NON-NLS-1$
50
private static final char[] SIGNATURE_CHARS = SIGNATURE.toCharArray();
50
private static final char[] SIGNATURE_CHARS = SIGNATURE.toCharArray();
51
public static boolean DEBUG = false;
51
public static boolean DEBUG = false;
52
52
Lines 132-138 Link Here
132
	}
132
	}
133
	return results;
133
	return results;
134
}
134
}
135
private HashtableOfObject addQueryResult(HashtableOfObject results, char[] word, HashtableOfObject wordsToDocNumbers, MemoryIndex memoryIndex) throws IOException {
135
private HashtableOfObject addQueryResult(HashtableOfObject results, char[] word, Object wordsToDocNumbers, MemoryIndex memoryIndex) throws IOException {
136
	// must skip over documents which have been added/changed/deleted in the memory index
136
	// must skip over documents which have been added/changed/deleted in the memory index
137
	if (results == null)
137
	if (results == null)
138
		results = new HashtableOfObject(13);
138
		results = new HashtableOfObject(13);
Lines 141-151 Link Here
141
		if (result == null)
141
		if (result == null)
142
			results.put(word, new EntryResult(word, wordsToDocNumbers));
142
			results.put(word, new EntryResult(word, wordsToDocNumbers));
143
		else
143
		else
144
			result.addDocumentTable(wordsToDocNumbers);
144
			result.addDocument(wordsToDocNumbers);
145
	} else {
145
	} else {
146
		SimpleLookupTable docsToRefs = memoryIndex.docsToReferences;
146
		SimpleLookupTable docsToRefs = memoryIndex.docsToReferences;
147
		if (result == null) result = new EntryResult(word, null);
147
		if (result == null) result = new EntryResult(word, null);
148
		int[] docNumbers = readDocumentNumbers(wordsToDocNumbers.get(word));
148
		int[] docNumbers = readDocumentNumbers(wordsToDocNumbers);
149
		for (int i = 0, l = docNumbers.length; i < l; i++) {
149
		for (int i = 0, l = docNumbers.length; i < l; i++) {
150
			String docName = readDocumentName(docNumbers[i]);
150
			String docName = readDocumentName(docNumbers[i]);
151
			if (!docsToRefs.containsKey(docName))
151
			if (!docsToRefs.containsKey(docName))
Lines 170-176 Link Here
170
					results = new HashtableOfObject(wordsToDocNumbers.elementSize);
170
					results = new HashtableOfObject(wordsToDocNumbers.elementSize);
171
				for (int j = 0, m = words.length; j < m; j++)
171
				for (int j = 0, m = words.length; j < m; j++)
172
					if (words[j] != null)
172
					if (words[j] != null)
173
						results = addQueryResult(results, words[j], wordsToDocNumbers, memoryIndex);
173
						results = addQueryResult(results, words[j], wordsToDocNumbers.valueTable[j], memoryIndex);
174
			}
174
			}
175
		}
175
		}
176
		if (results != null && this.cachedChunks == null)
176
		if (results != null && this.cachedChunks == null)
Lines 180-187 Link Here
180
			case SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE:
180
			case SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE:
181
				for (int i = 0, l = categories.length; i < l; i++) {
181
				for (int i = 0, l = categories.length; i < l; i++) {
182
					HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false);
182
					HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false);
183
					if (wordsToDocNumbers != null && wordsToDocNumbers.containsKey(key))
183
					Object value;
184
						results = addQueryResult(results, key, wordsToDocNumbers, memoryIndex);
184
					if (wordsToDocNumbers != null && ((value = wordsToDocNumbers.get(key)) != null))
185
						results = addQueryResult(results, key, value, memoryIndex);
185
				}
186
				}
186
				break;
187
				break;
187
			case SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE:
188
			case SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE:
Lines 192-198 Link Here
192
						for (int j = 0, m = words.length; j < m; j++) {
193
						for (int j = 0, m = words.length; j < m; j++) {
193
							char[] word = words[j];
194
							char[] word = words[j];
194
							if (word != null && key[0] == word[0] && CharOperation.prefixEquals(key, word))
195
							if (word != null && key[0] == word[0] && CharOperation.prefixEquals(key, word))
195
								results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex);
196
								results = addQueryResult(results, word, wordsToDocNumbers.valueTable[j], memoryIndex);
196
						}
197
						}
197
					}
198
					}
198
				}
199
				}
Lines 205-211 Link Here
205
						for (int j = 0, m = words.length; j < m; j++) {
206
						for (int j = 0, m = words.length; j < m; j++) {
206
							char[] word = words[j];
207
							char[] word = words[j];
207
							if (word != null && Index.isMatch(key, word, matchRule))
208
							if (word != null && Index.isMatch(key, word, matchRule))
208
								results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex);
209
								results = addQueryResult(results, word, wordsToDocNumbers.valueTable[j], memoryIndex);
209
						}
210
						}
210
					}
211
					}
211
				}
212
				}
Lines 613-618 Link Here
613
		this.bufferIndex = 0;
614
		this.bufferIndex = 0;
614
		this.bufferEnd = stream.read(this.streamBuffer, 0, this.streamBuffer.length);
615
		this.bufferEnd = stream.read(this.streamBuffer, 0, this.streamBuffer.length);
615
		int size = readStreamInt(stream);
616
		int size = readStreamInt(stream);
617
		int hashtablesize = readStreamInt(stream);
616
		try {
618
		try {
617
			if (size < 0) { // DEBUG
619
			if (size < 0) { // DEBUG
618
				System.err.println("-------------------- DEBUG --------------------"); //$NON-NLS-1$
620
				System.err.println("-------------------- DEBUG --------------------"); //$NON-NLS-1$
Lines 621-627 Link Here
621
				System.err.println("size = "+size); //$NON-NLS-1$
623
				System.err.println("size = "+size); //$NON-NLS-1$
622
				System.err.println("--------------------   END   --------------------"); //$NON-NLS-1$
624
				System.err.println("--------------------   END   --------------------"); //$NON-NLS-1$
623
			}
625
			}
624
			categoryTable = new HashtableOfObject(size);
626
			categoryTable = new HashtableOfObject(size, hashtablesize);
625
		} catch (OutOfMemoryError oom) {
627
		} catch (OutOfMemoryError oom) {
626
			// DEBUG
628
			// DEBUG
627
			oom.printStackTrace();
629
			oom.printStackTrace();
Lines 641-649 Link Here
641
			//		> 1 & < 256 then the size of the array is > 1 & < 256, the document array follows immediately
643
			//		> 1 & < 256 then the size of the array is > 1 & < 256, the document array follows immediately
642
			//		256 if the array size >= 256 followed by another int which is the offset to the array (written prior to the table)
644
			//		256 if the array size >= 256 followed by another int which is the offset to the array (written prior to the table)
643
			if (arrayOffset <= 0) {
645
			if (arrayOffset <= 0) {
644
				categoryTable.put(word, new int[] {-arrayOffset}); // store 1 element array by negating documentNumber
646
				categoryTable.putInOrder(word, new int[] {-arrayOffset}); // store 1 element array by negating documentNumber
645
			} else if (arrayOffset < largeArraySize) {
647
			} else if (arrayOffset < largeArraySize) {
646
				categoryTable.put(word, readStreamDocumentArray(stream, arrayOffset)); // read in-lined array providing size
648
				categoryTable.putInOrder(word, readStreamDocumentArray(stream, arrayOffset)); // read in-lined array providing size
647
			} else {
649
			} else {
648
				arrayOffset = readStreamInt(stream); // read actual offset
650
				arrayOffset = readStreamInt(stream); // read actual offset
649
				if (readDocNumbers) {
651
				if (readDocNumbers) {
Lines 653-659 Link Here
653
						firstOffset = arrayOffset;
655
						firstOffset = arrayOffset;
654
					matchingWords[count++] = word;
656
					matchingWords[count++] = word;
655
				}
657
				}
656
				categoryTable.put(word, new Integer(arrayOffset)); // offset to array in the file
658
				categoryTable.putInOrder(word, new Integer(arrayOffset)); // offset to array in the file
657
			}
659
			}
658
		}
660
		}
659
		this.categoryTables.put(INTERNED_CATEGORY_NAMES.get(categoryName), categoryTable);
661
		this.categoryTables.put(INTERNED_CATEGORY_NAMES.get(categoryName), categoryTable);
Lines 1060-1065 Link Here
1060
	this.categoryOffsets.put(categoryName, this.streamEnd); // remember the offset to the start of the table
1062
	this.categoryOffsets.put(categoryName, this.streamEnd); // remember the offset to the start of the table
1061
	this.categoryTables.put(categoryName, null); // flush cached table
1063
	this.categoryTables.put(categoryName, null); // flush cached table
1062
	writeStreamInt(stream, wordsToDocs.elementSize);
1064
	writeStreamInt(stream, wordsToDocs.elementSize);
1065
	writeStreamInt(stream, wordsToDocs.valueTable.length);
1063
	char[][] words = wordsToDocs.keyTable;
1066
	char[][] words = wordsToDocs.keyTable;
1064
	for (int i = 0, l = words.length; i < l; i++) {
1067
	for (int i = 0, l = words.length; i < l; i++) {
1065
		Object o = values[i];
1068
		Object o = values[i];
(-)search/org/eclipse/jdt/internal/core/index/EntryResult.java (-17 / +16 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-52 Link Here
11
package org.eclipse.jdt.internal.core.index;
11
package org.eclipse.jdt.internal.core.index;
12
12
13
import org.eclipse.jdt.core.compiler.CharOperation;
13
import org.eclipse.jdt.core.compiler.CharOperation;
14
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
15
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
14
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
16
15
17
public class EntryResult {
16
public class EntryResult {
18
17
19
private char[] word;
18
private char[] word;
20
private HashtableOfObject[] documentTables;
19
private Object[] documents;
21
private SimpleSet documentNames;
20
private SimpleSet documentNames;
22
21
23
public EntryResult(char[] word, HashtableOfObject table) {
22
public EntryResult(char[] word, Object document) {
24
	this.word = word;
23
	this.word = word;
25
	if (table != null)
24
	if (document != null)
26
		this.documentTables = new HashtableOfObject[] {table};
25
		this.documents = new Object[] {document};
27
}
26
}
28
public void addDocumentName(String documentName) {
27
public void addDocumentName(String documentName) {
29
	if (this.documentNames == null)
28
	if (this.documentNames == null)
30
		this.documentNames = new SimpleSet(3);
29
		this.documentNames = new SimpleSet(3);
31
	this.documentNames.add(documentName);
30
	this.documentNames.add(documentName);
32
}
31
}
33
public void addDocumentTable(HashtableOfObject table) {
32
public void addDocument(Object document) {
34
	if (this.documentTables != null) {
33
	if (this.documents != null) {
35
		int length = this.documentTables.length;
34
		int length = this.documents.length;
36
		System.arraycopy(this.documentTables, 0, this.documentTables = new HashtableOfObject[length + 1], 0, length);
35
		System.arraycopy(this.documents, 0, this.documents = new Object[length + 1], 0, length);
37
		this.documentTables[length] = table;
36
		this.documents[length] = document;
38
	} else {
37
	} else {
39
		this.documentTables = new HashtableOfObject[] {table};
38
		this.documents = new Object[] {document};
40
	}
39
	}
41
}
40
}
42
public char[] getWord() {
41
public char[] getWord() {
43
	return this.word;
42
	return this.word;
44
}
43
}
45
public String[] getDocumentNames(Index index) throws java.io.IOException {
44
public String[] getDocumentNames(Index index) throws java.io.IOException {
46
	if (this.documentTables != null) {
45
	if (this.documents != null) {
47
		int length = this.documentTables.length;
46
		int length = this.documents.length;
48
		if (length == 1 && this.documentNames == null) { // have a single table
47
		if (length == 1 && this.documentNames == null) { // have a single table
49
			Object offset = this.documentTables[0].get(this.word);
48
			Object offset = this.documents[0];
50
			int[] numbers = index.diskIndex.readDocumentNumbers(offset);
49
			int[] numbers = index.diskIndex.readDocumentNumbers(offset);
51
			String[] names = new String[numbers.length];
50
			String[] names = new String[numbers.length];
52
			for (int i = 0, l = numbers.length; i < l; i++)
51
			for (int i = 0, l = numbers.length; i < l; i++)
Lines 55-61 Link Here
55
		}
54
		}
56
55
57
		for (int i = 0; i < length; i++) {
56
		for (int i = 0; i < length; i++) {
58
			Object offset = this.documentTables[i].get(this.word);
57
			Object offset = this.documents[i];
59
			int[] numbers = index.diskIndex.readDocumentNumbers(offset);
58
			int[] numbers = index.diskIndex.readDocumentNumbers(offset);
60
			for (int j = 0, k = numbers.length; j < k; j++)
59
			for (int j = 0, k = numbers.length; j < k; j++)
61
				addDocumentName(index.diskIndex.readDocumentName(numbers[j]));
60
				addDocumentName(index.diskIndex.readDocumentName(numbers[j]));
Lines 74-79 Link Here
74
	return names;
73
	return names;
75
}
74
}
76
public boolean isEmpty() {
75
public boolean isEmpty() {
77
	return this.documentTables == null && this.documentNames == null;
76
	return this.documents == null && this.documentNames == null;
78
}
77
}
79
}
78
}

Return to bug 289057