22 |
*/ |
*/ |
23 |
package gzz.vob; |
package gzz.vob; |
24 |
class OrthoCoordsysMap { |
class OrthoCoordsysMap { |
|
OrthoCoordsys sys; |
|
|
int[] hashtable; |
|
|
boolean canInterpolate; |
|
|
|
|
|
OrthoCoordsysMap(OrthoCoordsys sys, int initialSize) { |
|
|
this.sys = sys; |
|
|
hashtable = new int[initialSize]; |
|
|
canInterpolate = true; |
|
|
} |
|
|
|
|
|
void clear() { |
|
|
for(int i=0; i<hashtable.length; i++) |
|
|
hashtable[i] = 0; |
|
|
canInterpolate = true; |
|
|
} |
|
|
|
|
|
final int hash(int cs) { |
|
|
return Math.abs(sys.key[cs].hashCode()) ^ sys.parent[cs]; |
|
|
} |
|
|
|
|
|
void add(int cs) { |
|
|
if(sys.key[cs] == null) return; |
|
|
if(get(sys.parent[cs], sys.key[cs]) >= 0) { |
|
|
canInterpolate = false; return; |
|
|
} |
|
|
|
|
|
if(sys.nsys > hashtable.length) { rehash(); return; } |
|
|
|
|
|
int i = hash(cs) % hashtable.length; |
|
|
sys.nextHashtableEntry[cs] = hashtable[i]; |
|
|
hashtable[i] = cs; |
|
|
} |
|
|
|
|
|
int get(int parent, Object key) { |
|
|
if(key == null) return -1; |
|
|
int hash = Math.abs(key.hashCode()) ^ parent; |
|
|
int i = hash % hashtable.length; |
|
|
int cs = hashtable[i]; |
|
|
while(cs > 0) { |
|
|
if(parent == sys.parent[cs]) |
|
|
if(key.equals(sys.key[cs])) |
|
|
return cs; |
|
|
|
|
|
cs = sys.nextHashtableEntry[cs]; |
|
|
} |
|
|
return -1; |
|
|
} |
|
|
|
|
|
void rehash() { |
|
|
hashtable = new int[sys.nsys * 2]; |
|
|
for(int i=1; i<sys.nsys; i++) |
|
|
add(i); |
|
|
} |
|
25 |
} |
} |