Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Finish the implimentation of the toString method given the specifications of the rest of the code. import java.util.Iterator; public class ProbeHashTable extends AbstractHashMap{ private MapEntry[]

Finish the implimentation of the toString method given the specifications of the rest of the code.

import java.util.Iterator;

public class ProbeHashTable extends AbstractHashMap{

private MapEntry[] table;

private MapEntry DEFUNCT = new MapEntry(null, null);

private int count = 0;

public ProbeHashTable() {

super();

}

public ProbeHashTable(int cap) {

super();

}

public ProbeHashTable(int cap,int p) {

super(cap, p);

}

private boolean compareStr(String s, String t) {

count++;

return s.equals(t);

}

protected void createTable() {

table = (MapEntry[]) new MapEntry[capacity];

}

private boolean isAvailable(int i) {

return (table[i] == null || table[i] == DEFUNCT);

}

private int findSlot(int h, String k) {

int available = -1;

int i = h;

do {

if(isAvailable(i)) {

if(available == -1)

available = i;

if(table[i] == null)

break;

}

else if(table[i].getKey().equals(k))

return i;

i = (i + 1) % capacity;

}

while(i != h);

return -(available + 1);

}

protected Object bucketPut(int h, Object key, Object value) {

int i = findSlot(h, (String) key);

if(i < 0)

return table[i].setValue((String) value);

table[-(i + 1)] = new MapEntry(key, value);

n++;

return null;

}

protected Object bucketGet(int h, Object key) {

int i = findSlot(h, (String) key);

if(i < 0)

return null;

return table[i].getValue();

}

protected Object bucketRemove(int h, Object key) {

int i = findSlot(h, (String) key);

if(i < 0)

return null;

Object answer = table[i].getValue();

table[i] = DEFUNCT;

n--;

return answer;

}

private class KeyIterable implements Iterable{

public Iterator iterator() {

ArrayList buffer = new ArrayList(n);

for(int i = 0; i < capacity; i++)

try {

if(!isAvailable(i))

buffer.add(buffer.size(), table[i].getKey());

}

catch(OutOfRangeException e) {

System.out.println("keySet: Out Of Range");

}

return new SArrayIterator(buffer);

}

}

public Iterable keySet() {

return new KeyIterable();

}

public int getCollisions(){

return count;

}

public String toString() {

// convert the ProbeHashTable object to a string in the format of

 // "index key value" tuples, for example // 0 Streater WR // 6 Stanton QB // 9 Watford G // ... }

}

public abstract class AbstractMap { public abstract Object get(Object key); public abstract Object put(Object key, Object value); public abstract Object remove(Object key); public abstract boolean isEmpty(); public abstract int size(); public abstract Iterable keySet();

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions

Question

Understanding Groups

Answered: 1 week ago

Question

how will you handle the $886000 in the obsolete inventory

Answered: 1 week ago