Using Java, fill the ¨you must implement¨ spots... import java.util.Map; import
ID: 3761630 • Letter: U
Question
Using Java, fill the ¨you must implement¨ spots...
import java.util.Map;
import java.util.Iterator;
public interface HashFunction<AnyType>
{
int hashCode( AnyType x );
}
public class MyHashMap<KeyType,ValueType> implements Iterable<Map.Entry<KeyType,ValueType>>
{
private HashFunction<KeyType> hash1;
private HashFunction<KeyType> hash2;
public MyHashMap( HashFunction<KeyType> h1, HashFunction<KeyType> h2 )
{ /* You must implement */ }
public int size( )
{ /* You must implement */ }
public void clear( )
{ /* You must implement */ }
public ValueType put( KeyType k, ValueType v )
{ /* You must implement */ }
Explanation / Answer
public int size( )
{
return theSet.size( );
}
public void clear( )
{
theSet.clear( );
}
public ValueType put( KeyType key, ValueType value )
{
Map.Entry<KeyType,ValueType> match = theSet.getMatch( makePair( key ) );
if( match != null )
return match.setValue( value );
theSet.add( makePair( key, value ) );
return null;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.