Hash table7/9/2023 ![]() ![]() The function itself throws an (unchecked) exception, theĮxception is rethrown, and no mapping is recorded. If the function returns null no mapping is recorded. To null), attempts to compute its value using the given mappingįunction and enters it into this map unless null. If the specified key is not already associated with a value (or is mapped Highly-concurrent implementation is desired, then it is recommended Thread-safe implementation is not needed, it is recommended to use Implementations, Hashtable is synchronized. Implement the Map interface, making it a member of the Therefore, it would be wrong to write a program that depended on thisĮxception for its correctness: the fail-fast behavior of iteratorsĪs of the Java 2 platform v1.2, this class was retrofitted to Throw ConcurrentModificationException on a best-effort basis. Presence of unsynchronized concurrent modification. Note that the fail-fast behavior of an iterator cannot be guaranteedĪs it is, generally speaking, impossible to make any hard guarantees in the The Enumerations returned by Hashtable's keys and elements methods are Modification, the iterator fails quickly and cleanly, rather than riskingĪrbitrary, non-deterministic behavior at an undetermined time in the future. Remove method, the iterator will throw a ConcurrentModificationException. Returned by all of this class's "collection view methods" areįail-fast: if the Hashtable is structurally modified at any timeĪfter the iterator is created, in any way except through the iterator's own The iterators returned by the iterator method of the collections To retrieve a number, use the following code: This example creates a hashtable of numbers. If many entries are to be made into a Hashtable,Ĭreating it with a sufficiently large capacity may allow theĮntries to be inserted more efficiently than letting it performĪutomatic rehashing as needed to grow the table. Setting the initial capacity too high can waste space. Hashtable will contain divided by its load factor. No rehash operations will ever occur if the initialĬapacity is greater than the maximum number of entries the Need for rehash operations, which are time-consuming. The initial capacity controls a tradeoff between wasted space and the Hashtable operations, including get and put). Increase the time cost to look up an entry (which is reflected in most Higher values decrease the space overhead but Generally, the default load factor (.75) offers a good tradeoff between Method is invoked are implementation-dependent. The exact details as to when and whether the rehash The initial capacity and load factor parameters are merely hints to Table is allowed to get before its capacity is automatically increased. The load factor is a measure of how full the hash Note that the hash table is open: in the case of a "hashĬollision", a single bucket stores multiple entries, which must be searched Initial capacity is simply the capacity at the time the hash table TheĬapacity is the number of buckets in the hash table, and the Performance: initial capacity and load factor. Objects used as keys must implement the hashCodeĪn instance of Hashtable has two parameters that affect its To successfully store and retrieve objects from a hashtable, the Non- null object can be used as a key or as a value. This class implements a hash table, which maps keys to values.
0 Comments
Leave a Reply. |