经典Hash实现(采用拉链法处理冲突)
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
* must be greater than current capacity unless current
* capacity is MAXIMUM_CAPACITY(in which case value
* is irrelevant)。
*/
final private void resize(int newCapacity){
Entry[] newTable = new Entry[newCapacity];
transfer(newTable);奥术神座:www.laibigu.com
table = newTable;
threshold =(int)(newCapacity * 0.75f);
}
/**
* Transfer all entries from current table to newTable.
* resize the map, but but sets threshold to Integer.MAX_VALUE.
* This has the effect of preventing future calls.
*
* @param newCapacity the new capacity, MUST be a power of two;
}else{
Entry entry = newTable[i];
while(entry.next != null)entry = entry.next;
entry.next = e;
}
e = next;
} while(e != null);
}
}
}
/**
* Removes the mapping for this key from this map if present.
*/
final TableStorePage get(long key) {
int i = (int)(key % table.length);
Entry e = table[i];人皇:www.renhuang.net
while (true) {
if (e == null)
return null;
Entry prev = table[i];
Entry e = prev;
while(e != null){
Entry next = e.next;
if(e.key == key){
size--;
if(prev == e)
table[i] = next;
else
prev.next = next;
return e.value;
table[i] = new Entry(key, value, table[i]);
if(size++ >= threshold)
resize(2 * table.length);
return null;
}
/**
* Rehashes the contents of this map into a new array with a
* also indicate that the map previously associated <tt>null</tt>
* with the specified key.
*/
final TableStorePage remove(long key){九星天辰诀:www.dizun.cc
int i =(int)(key % table.length);
if (e.key == key)
return e.value;
e = e.next;
}
}
/**
* Returns <tt>true</tt> if this map contains a StorePage for the
* specified key.
*
*/
final boolean containsKey(long key) {
*
* @return <tt>true</tt> if this map contains no key-value mappings.
*/
final boolean isEmpty() {
return size == 0;
}
/**
* Returns the first StorePage for the given key.
if(e != null){
src[j] = null;
do {
Entry next = e.next;
e.next = null;
int i =(int)(e.key % newCapacity);
//The order for StorePages with the same key must not change
final long key;
final TableStorePage value;
Entry next;
/**
* Create new entry.
*/
Entry(long k, TableStorePage v, Entry n){
value = v;
next = n;
key = k;
}
}
}
*/
final private void transfer(Entry[] newTable){
Entry[] src = table;
int newCapacity = newTable.length;
for(int j = 0; j < src.length; j++){
Entry e = src[j];
}
prev = e;
e = next;
}
return null;
}
/**
* Removes all mappings from this map.
*/
final void clear(){
Entry tab[] = table;
for(int i = 0; i < tab.length; i++)
tab[i] = null;
*
* @return the number of key-value mappings in this map.
*/天骄无双:www.22bl.com
final int size() {
return size;
}
/**
* Returns <tt>true</tt> if this map contains no key-value mappings.
return (get(key) != null);
}
/**
* Add the StorePage with the key. Multiple StorePage for the same key are valid.
* The cause are multiple changes in one transaction. With SavePoints a rollback to a older
* larger capacity. This method is called automatically when the
* number of keys in this map reaches its threshold.
*
* If current capacity is MAXIMUM_CAPACITY, this method does not
class StorePageMap {
/**
* The table, resized as necessary. Length MUST Always be a power of two.
*/
private Entry[] table;
/**
* The number of key-value mappings contained in this identity hash map.
* @return <tt>true</tt> if this map maps one or more keys to the
* specified value.
*/
final boolean containsValue(TableStorePage value){
Entry tab[] = table;
//that we need to find the end of the link list. This is different to a typical HashTable
if(newTable[i] == null){天骄无双:www.tianjiaoba.com
newTable[i] = e;
*/
private int size;
/**
* The next size value at which to resize (capacity * load factor)。
* @serial不败战神:www.qiuyeyu.com
*/
private int threshold;
/**
* Constructs an empty <tt>HashMap</tt> with the default initial capacity
for(int i = 0; i < tab.length ; i++)
for(Entry e = tab[i] ; e != null ; e = e.next)
if(value.equals(e.value))
return true;
return false;
}
static class Entry{
size = 0;
}天骄无双:www.qubilou.com
/**
* Returns <tt>true</tt> if this map maps one or more keys to the
* specified value.
*
* @param value value whose presence in this map is to be tested.
* (16) and the default load factor (0.75)。
*/
StorePageMap() {
threshold = 12;
table = new Entry[17];
}
/**
* Returns the number of key-value mappings in this map.
* StorePage is valid.<p>斩龙:www.luoyege.net
* The latest StorePage is placed at f源自文库rst pos.
*/
final TableStorePage add(long key, TableStorePage value){
int i =(int)(key % table.length);
*
* @param key key whose mapping is to be removed from the map.
* @return previous value associated with specified key, or <tt>null</tt>
* if there was no mapping for key. A <tt>null</tt> return can
* capacity is MAXIMUM_CAPACITY(in which case value
* is irrelevant)。
*/
final private void resize(int newCapacity){
Entry[] newTable = new Entry[newCapacity];
transfer(newTable);奥术神座:www.laibigu.com
table = newTable;
threshold =(int)(newCapacity * 0.75f);
}
/**
* Transfer all entries from current table to newTable.
* resize the map, but but sets threshold to Integer.MAX_VALUE.
* This has the effect of preventing future calls.
*
* @param newCapacity the new capacity, MUST be a power of two;
}else{
Entry entry = newTable[i];
while(entry.next != null)entry = entry.next;
entry.next = e;
}
e = next;
} while(e != null);
}
}
}
/**
* Removes the mapping for this key from this map if present.
*/
final TableStorePage get(long key) {
int i = (int)(key % table.length);
Entry e = table[i];人皇:www.renhuang.net
while (true) {
if (e == null)
return null;
Entry prev = table[i];
Entry e = prev;
while(e != null){
Entry next = e.next;
if(e.key == key){
size--;
if(prev == e)
table[i] = next;
else
prev.next = next;
return e.value;
table[i] = new Entry(key, value, table[i]);
if(size++ >= threshold)
resize(2 * table.length);
return null;
}
/**
* Rehashes the contents of this map into a new array with a
* also indicate that the map previously associated <tt>null</tt>
* with the specified key.
*/
final TableStorePage remove(long key){九星天辰诀:www.dizun.cc
int i =(int)(key % table.length);
if (e.key == key)
return e.value;
e = e.next;
}
}
/**
* Returns <tt>true</tt> if this map contains a StorePage for the
* specified key.
*
*/
final boolean containsKey(long key) {
*
* @return <tt>true</tt> if this map contains no key-value mappings.
*/
final boolean isEmpty() {
return size == 0;
}
/**
* Returns the first StorePage for the given key.
if(e != null){
src[j] = null;
do {
Entry next = e.next;
e.next = null;
int i =(int)(e.key % newCapacity);
//The order for StorePages with the same key must not change
final long key;
final TableStorePage value;
Entry next;
/**
* Create new entry.
*/
Entry(long k, TableStorePage v, Entry n){
value = v;
next = n;
key = k;
}
}
}
*/
final private void transfer(Entry[] newTable){
Entry[] src = table;
int newCapacity = newTable.length;
for(int j = 0; j < src.length; j++){
Entry e = src[j];
}
prev = e;
e = next;
}
return null;
}
/**
* Removes all mappings from this map.
*/
final void clear(){
Entry tab[] = table;
for(int i = 0; i < tab.length; i++)
tab[i] = null;
*
* @return the number of key-value mappings in this map.
*/天骄无双:www.22bl.com
final int size() {
return size;
}
/**
* Returns <tt>true</tt> if this map contains no key-value mappings.
return (get(key) != null);
}
/**
* Add the StorePage with the key. Multiple StorePage for the same key are valid.
* The cause are multiple changes in one transaction. With SavePoints a rollback to a older
* larger capacity. This method is called automatically when the
* number of keys in this map reaches its threshold.
*
* If current capacity is MAXIMUM_CAPACITY, this method does not
class StorePageMap {
/**
* The table, resized as necessary. Length MUST Always be a power of two.
*/
private Entry[] table;
/**
* The number of key-value mappings contained in this identity hash map.
* @return <tt>true</tt> if this map maps one or more keys to the
* specified value.
*/
final boolean containsValue(TableStorePage value){
Entry tab[] = table;
//that we need to find the end of the link list. This is different to a typical HashTable
if(newTable[i] == null){天骄无双:www.tianjiaoba.com
newTable[i] = e;
*/
private int size;
/**
* The next size value at which to resize (capacity * load factor)。
* @serial不败战神:www.qiuyeyu.com
*/
private int threshold;
/**
* Constructs an empty <tt>HashMap</tt> with the default initial capacity
for(int i = 0; i < tab.length ; i++)
for(Entry e = tab[i] ; e != null ; e = e.next)
if(value.equals(e.value))
return true;
return false;
}
static class Entry{
size = 0;
}天骄无双:www.qubilou.com
/**
* Returns <tt>true</tt> if this map maps one or more keys to the
* specified value.
*
* @param value value whose presence in this map is to be tested.
* (16) and the default load factor (0.75)。
*/
StorePageMap() {
threshold = 12;
table = new Entry[17];
}
/**
* Returns the number of key-value mappings in this map.
* StorePage is valid.<p>斩龙:www.luoyege.net
* The latest StorePage is placed at f源自文库rst pos.
*/
final TableStorePage add(long key, TableStorePage value){
int i =(int)(key % table.length);
*
* @param key key whose mapping is to be removed from the map.
* @return previous value associated with specified key, or <tt>null</tt>
* if there was no mapping for key. A <tt>null</tt> return can