All pastes #2110911 Raw Edit

Stuff

public text v1 · immutable
#2110911 ·published 2012-02-07 19:12 UTC
rendered paste body
#ifndef DYNAMIC_DOUBLE_HASH_TABLE_H
#define DYNAMIC_DOUBLE_HASH_TABLE_H

/*****************************************
 * UW User ID:  uwuserid
 * Submitted for ECE 250
 * Semester of Submission:  (Winter|Spring|Fall) 20NN
 *
 * By submitting this file, I affirm that
 * I am the author of all modifications to
 * the provided code.
 *****************************************/

#include "Exception.h"
#include "ece250.h"

enum state { EMPTY, OCCUPIED, DELETED };

template<typename Type>
class Dynamic_double_hash_table {
	private:
		int power;
		int count;
		int deleted_count;
		int array_size;
		int initial_size;

		Type *array;
		state *occupied;

		int h1( Type const & ) const;
		int h2( Type const & ) const;
	public:
		Dynamic_double_hash_table( int = 5 );
		~Dynamic_double_hash_table();
		int size() const;
		int capacity() const;
		double load_factor() const;
		double deleted_factor() const;
		bool empty() const;
		bool member( Type const & ) const;
		Type bin( int ) const;

		void print() const;

		void insert( Type const & );
		bool remove( Type const & );
		void clear();

	// Friends

	template <typename T>
	friend std::ostream &operator << ( std::ostream &, Dynamic_double_hash_table<T> const & );
};

template<typename Type>
Dynamic_double_hash_table<Type>::Dynamic_double_hash_table( int m ):
power( m ), count( 0 ), deleted_count( 0 ),
array_size( 1 << power ),
initial_size( 1 << power ),
array( new Type[array_size] ),
occupied( new state[array_size] ) {
	for ( int i = 0; i < array_size; ++i ) {
		occupied[i] = EMPTY;
	}
}

template<typename Type>
Dynamic_double_hash_table<Type>::~Dynamic_double_hash_table() { // i did this
	delete [] array;

}

template<typename Type>
int Dynamic_double_hash_table<Type>::size() const { // i did this
        return array_size;
}

template<typename Type>
int Dynamic_double_hash_table<Type>::capacity() const { // i did this
	int occnum = 0;
	for ( int i = 0; i < array_size; ++i ) {
		if (occupied[i] == EMPTY) {
			occnum++;
		}
	}
	return occnum;
}

template<typename Type>
double Dynamic_double_hash_table<Type>::load_factor() const {
        // enter your implementation here
	return 0.0;
}

template<typename Type>
double Dynamic_double_hash_table<Type>::deleted_factor() const {
        // enter your implementation here
	return 0.0;
}

template<typename Type>
bool Dynamic_double_hash_table<Type>::empty() const {
        // enter your implementation here
	return true;
}

template<typename Type>
int Dynamic_double_hash_table<Type>::h1( Type const &obj ) const {
	int result = static_cast<int>( obj ) & (array_size - 1);

	return result < 0 ? (result + array_size) : result;
}

template<typename Type>
int Dynamic_double_hash_table<Type>::h2( Type const &obj ) const {
	int result = (static_cast<int>( obj ) / array_size) & (array_size - 1);

	return (result < 0) ? ((result + array_size) | 1) : (result | 1);
}

template<typename Type>
bool Dynamic_double_hash_table<Type>::member( Type const &obj ) const {
  // enter your implementation here	
  return false;
}

template<typename Type>
Type Dynamic_double_hash_table<Type>::bin( int n ) const {
	// DO NOT CHANGE
	return array[n];
}

template<typename Type>
void Dynamic_double_hash_table<Type>::insert( Type const &obj ) {
    // enter your implementation here
}

template<typename Type>
bool Dynamic_double_hash_table<Type>::remove( Type const &obj ) {
       // enter your implementation here
	return false;
}

template<typename Type>
void Dynamic_double_hash_table<Type>::clear() {
    // enter your implementation here
}


// You can modify this function however you want:  it will not be tested

template <typename T>
std::ostream &operator << ( std::ostream &out, Dynamic_double_hash_table<T> const &list ) {
	return out;
}

// Is an error showing up in ece250.h or elsewhere?
// Did you forget a closing '}' ?

#endif