至于hashMap的原理,我想不必多说,大家都清楚,直接上代码啦
HashMap.h
#ifndef HashMap_H
#define HashMap_H
#include "iostream"
#include "boost/thread/mutex.hpp"
#include "boost/thread/shared_mutex.hpp"
const int HM_SIZE=200;
struct Node{
int key;
int value;
Node* next;
Node(int k,int v):key(k),value(v),next(NULL)
{
}
};
class HashMap{
public:
HashMap();
~HashMap();
void insert(int key,int value);
void remove(int key);
Node* find(int key);
size_t size();
private:
int hash(int key) const;
private:
size_t m_nSize;
Node** m_map;
boost::shared_mutex m_rwMutex[HM_SIZE/5];//共享互斥信号量
};
#endif;<