< prev index next >
src/hotspot/share/utilities/hashtable.hpp
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 299,323 ****
}
public:
KVHashtable(int table_size) : BasicHashtable<F>(table_size, sizeof(KVHashtableEntry)) {}
! void add(K key, V value) {
unsigned int hash = HASH(key);
KVHashtableEntry* entry = new_entry(hash, key, value);
BasicHashtable<F>::add_entry(BasicHashtable<F>::hash_to_index(hash), entry);
}
! V* lookup(K key) {
unsigned int hash = HASH(key);
int index = BasicHashtable<F>::hash_to_index(hash);
for (KVHashtableEntry* e = bucket(index); e != NULL; e = e->next()) {
if (e->hash() == hash && e->_key == key) {
return &(e->_value);
}
}
return NULL;
}
};
#endif // SHARE_UTILITIES_HASHTABLE_HPP
--- 299,341 ----
}
public:
KVHashtable(int table_size) : BasicHashtable<F>(table_size, sizeof(KVHashtableEntry)) {}
! V* add(K key, V value) {
unsigned int hash = HASH(key);
KVHashtableEntry* entry = new_entry(hash, key, value);
BasicHashtable<F>::add_entry(BasicHashtable<F>::hash_to_index(hash), entry);
+ return &(entry->_value);
}
! V* lookup(K key) const {
unsigned int hash = HASH(key);
int index = BasicHashtable<F>::hash_to_index(hash);
for (KVHashtableEntry* e = bucket(index); e != NULL; e = e->next()) {
if (e->hash() == hash && e->_key == key) {
return &(e->_value);
}
}
return NULL;
}
+
+ int table_size() const {
+ return BasicHashtable<F>::table_size();
+ }
+
+ // ITER contains bool do_entry(K, V const&), which will be
+ // called for each entry in the table. If do_entry() returns false,
+ // the iteration is cancelled.
+ template<class ITER>
+ void iterate(ITER* iter) const {
+ for (int index = 0; index < table_size(); index++) {
+ for (KVHashtableEntry* e = bucket(index); e != NULL; e = e->next()) {
+ bool cont = iter->do_entry(e->_key, &e->_value);
+ if (!cont) { return; }
+ }
+ }
+ }
};
#endif // SHARE_UTILITIES_HASHTABLE_HPP
< prev index next >