Mercurial > jhg
annotate src/org/tmatesoft/hg/util/DirectHashSet.java @ 446:9f0e6dfd417e smartgit3
Workaround for a Revlog#walk defect for the price of (almost) complete repo walk
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 05 Jun 2012 21:18:20 +0200 |
parents | 85b8efde5586 |
children | 51d682cf9cdc |
rev | line source |
---|---|
304
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011 TMate Software Ltd |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.util; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import org.tmatesoft.hg.internal.Experimental; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 /** |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 * Memory-friendly alternative to HashSet. With slightly worse performance than that of HashSet, uses n * sizeof(HashMap.Entry) less memory |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 * (i.e. for set of 50k elements saves more than 1 Mb of memory). Besides, elements of this set can be obtained (not only queried for presence) - |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 * the option essential for canonical mappings (aka Pool) |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 * |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 * @author Artem Tikhomirov |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 * @author TMate Software Ltd. |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 */ |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 @Experimental |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 public class DirectHashSet<T> { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 private Object[] table; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 private int size; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 private int threshold; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 public DirectHashSet() { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 this (16); |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 public DirectHashSet(int capacity) { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 int result = 2; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 while (result < capacity) { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 result <<= 1; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 table = new Object[result]; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 threshold = result - (result >>> 2); |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 /** |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 * Add element to the set. |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 * @param o element, shall not be <code>null</code> |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 * @return previous element from the set equal to the argument |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 */ |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 @SuppressWarnings("unchecked") |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 public T put(T o) { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 final int h = hash(o); |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 final int mask = table.length - 1; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 int i = h & mask; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 Object t; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 while ((t = table[i]) != null) { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 if (t.equals(o)) { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 table[i] = o; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 return (T) t; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 i = (i+1) & mask; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 table[i] = o; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 if (++size >= threshold) { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 resize(); |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 return null; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 /** |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 * Query set for the element. |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 * @param o element, shall not be <code>null</code> |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 * @return element from the set, if present |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 */ |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 @SuppressWarnings("unchecked") |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 public T get(T o) { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 final int h = hash(o); |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 final int mask = table.length - 1; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 int i = h & mask; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 Object t; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 while ((t = table[i]) != null) { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 if (t == o || t.equals(o)) { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 return (T) t; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 i = (i+1) & mask; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 return null; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 public int size() { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 return size; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 public void clear() { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 Object[] t = table; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 for (int i = 0, top = t.length; i < top; i++) { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 t[i] = null; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 size = 0; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 private void resize() { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 final int newSize = table.length << 1; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 final int newMask = newSize - 1; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 Object[] newTable = new Object[newSize]; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 for (int i = 0, size = table.length; i < size; i++) { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 Object t = table[i]; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 if (t != null) { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 table[i] = null; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 int x = hash(t) & newMask; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 while (newTable[x] != null) { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 x = (x+1) & newMask; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 newTable[x] = t; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 table = newTable; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 threshold = newSize - (newSize >>> 2); |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 private static int hash(Object o) { |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 int h = o.hashCode(); |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 // return h; |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 // HashMap.newHash() |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 h ^= (h >>> 20) ^ (h >>> 12); |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 return h ^ (h >>> 7) ^ (h >>> 4); |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 } |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 |
85b8efde5586
Use memory-friendly set implementation to canonicalize filenames and nodeids
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 } |