SeparateChainingHashTable - import java.util.Arrays; /* *...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.Arrays; i /** * Separate chaining table implementation of hash tables. * all "matching" is based on the equals method. */ public class SeparateChainingHashTable implements HashTable { /** * Construct the hash table. */ public SeparateChainingHashTable( ) { this( DEFAULT_TABLE_SIZE , 0.7); } /** * Construct the hash table. * @param cap approximate table size. * @param load_factor the load factor maximum of the hash table */ public SeparateChainingHashTable(int cap , double load_factor) { if ( load_factor <= 0.0 || load_factor > 1.0 )throw new IllegalArgumentException("load factor out of range"); I theLists = new SimpleLinkedList[ nextPrime(cap) ]; t for( int i = 0; i < theLists.length; i++ ) theLists[i] = new SimpleLinkedList( ); max_load_factor = load_factor; } /** * <p> Returns the number of elements in this structure. * @return int * </p> */ public int size() { int total_size = 0; for(int i = 0; i < theLists.length; i++) total_size += theLists[i].size(); t return total_size; } /** * <p> Returns true if this structure contains no elements. * @return boolean * </p> */ public boolean isEmpty() { return size() == 0;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
} /** * <p> Returns true if the current load factor exceeds * the load factor set in the constructor. * @return boolean
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/26/2010 for the course COMPUTER S Java2 taught by Professor Kwstasmixail during the Spring '10 term at Technical University of Crete.

Page1 / 6

SeparateChainingHashTable - import java.util.Arrays; /* *...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online