You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
774 B

//
// Created by Jaeha Choi on 2020-06-10.
//
#include "Hash.h"
#include <iostream>
using namespace std;
Hash::Hash(int size) : no_data(size), min(size), max(0){
vec = new vector<list<int>>(size);
for(auto & i : *vec){
i = list<int>();
}
}
void Hash::insert(int elem, int size) {
list<int> *li = &(vec->at(elem % size));
if (li->empty()){
no_data --;
}
li->push_back(elem);
if (li->size() > max){
max = li->size();
}
}
void Hash::show() {
for(auto & i : *vec){
if(i.size() < min){
min = i.size();
}
}
cout << "Size of the array: "<< vec->size() << endl;
cout << "Max num of collision: " << max << endl;
cout << "Min num of collision: " << min << endl;
cout << "Array elems with no data: " << no_data << endl;
}