//---------------------------15/03/26----------------------------

//hash_set

{

/*

hash_set概述:

1:这是一个hash版本的set,RB_tree版本的set有自动排序功能,

而hash_set没有这个功能。

2:hash_set的使用方式,与set完全相同。

*/

//class

template<class Value,
class HashFcn = hash<Value>,

class EqualKey = equal_to<Value>,
class Alloc=alloc>

class hash_set

{

private:

typedef hashtable<Value, Value, HashFcn, identity<Value>,

EqualKey, Alloc> ht;

ht rep;

public:

typedef typename ht::key_type key_type;

typedef typename ht::value_type value_type;

typedef typename ht::hasher hasher;        
//hashtable中: typedef HashFcn hasher

typedef typename ht::key_equel key_equel;

typedef typename ht::size_type size_type;

typedef typename ht::difference_type difference_type;

typedef typename ht::const_pointer pointer;

typedef typename ht::const_pointer const_pointer;

typedef typename ht::const_reference reference;

typedef typename ht::const_reference const_reference;

typedef typename ht::const_iterator iterator;

typedef typename ht::const_iterator const_iterator;

hasher hash_funct()
const {return rep.hash_funct(); }

key_equel key_eq()
const { return rep.key_eq(); }

public:

//各种构造函数 ,不给定大小的话默认值为100,实际上找到的质数为193

hash_set() : rep(,hasher(), key_equel()){}

explicit hash_set(size_type n) : rep(n, hasher(), key_equel()) {}

hash_set(size_type n,
const hasher& hf) : rep(n, hf, key_equel()) {}

hash_set(size_type n,
const hasher& hf,
const key_equel& eql)

: rep(n, hf, eql) {}

template< class InputIterator>

hash_set(InputIterator f, InputIterator l)

: rep(, hasher(), key_equel()) { rep.insert_unique(f, l); }

template< class InputIterator>

hash_set(InputIterator f, InputIterator l, size_type n)

: rep(n, hasher(), key_equel()) { rep.insert_unique(f, l); }

template< class InputIterator>

hash_set(InputIterator f, InputIterator l, size_type n,
const hasher& hf)

: rep(n, hf, key_equel()) { rep.insert_unique(f, l); }

template< class InputIterator>

hash_set(InputIterator f, InputIterator l, size_type n,
const hasher& hf

const key_equel& eql)

: rep(, hf, eql) { rep.insert_unique(f, l); }

public:

size_type size()
const {return rep.size();}

size_type max_size()
const { return rep.max_size(); }

bool empty() const {return rep.empty(); }

void swap(hash_set& hs) { rep.swap(hs.rep); }

friend bool
operator== __STL_NULL_TMPL_ARGS (const hash_set&,
const hash_set&);

iterator begin()
const { return rep.begin(); }

iterator end()
const { return rep.end(); }

public:

pair<iterator,
bool> insert(const value_type& obj)

{

pair<typename ht::iterator,
bool> p =rep.insert_unique(obj);

return pair<iterator,
bool>(p.first, p.second);

}

template<class InputIterator>

void insert(InputIterator f, InputIterator l) { rep.insert_unique(f,l); }

pair<iterator,
bool> insert_noresize(const value_type& obj)

{

pair<typename ht::iterator,
bool> p = rep.insert_unique_noresize(obj);

return pair<iterator,
bool>(p.first, p.second);

}

iterator find(const key_type& key)
const { return rep.find(key); }

size_type count(const key_type& key)
const {return rep.count(key); }

//相等的key的位置(是一个左闭右开的区间),由迭代器给出

pair<iterator, iterator> equal_range(const key_type& key)
const

{
return rep.equal_range(key); }

size_type erase(const key_type& key) {
return rep.erase(key); }

void erase(iterator it) { rep.erase(it); }

void erase(iterator f, iterator l) { rep.erase(f, l); }

void clear() { rep.clear(); }

public:

void    resize(size_type hint) { rep.resize(hint); }

size_type bucket_count()
const { return rep.bucket_count(); }

size_type elems_in_bucket(size_type n)
const

{
return rep.elems_in_bucket(n); }

//class

template<class Value,
class HashFcn, class EqualKey,
class Alloc>

inline bool
operator==(const hash_set<Value, HashFcn, EqualKey, Alloc>& hs1,

const hash_set<Value, HashFcn, EqualKey, Alloc>& hs2)

{

return has1.rep == has2.rep;

}

};

}

//hash_map

{

/*

hash_map概述:

hash_map之于map就像hash_set之于set一样。

*/

//class

template<class Key,
class T, class HashFcn = hash<Value>,

class EqualKey = equal_to<Value>,
class Alloc=alloc>

class hash_map

{

private:

typedef hashtable<pair<const Key, T>, Key, HashFcn,

select1st<pair<const Key, T>, EqualKey, Alloc> ht;

ht rep;

public:

typedef typename ht::key_type key_type;

typedef T data_type;

typedef T mapped_type;

typedef typename ht::value_type value_type;

typedef typename ht::hasher hasher;        
//hashtable中: typedef HashFcn hasher

typedef typename ht::key_equel key_equel;

typedef typename ht::size_type size_type;

typedef typename ht::difference_type difference_type;

typedef typename ht::pointer pointer;

typedef typename ht::const_pointer const_pointer;

typedef typename ht::reference reference;

typedef typename ht::const_reference const_reference;

typedef typename ht::iterator iterator;

typedef typename ht::const_iterator const_iterator;

hasher hash_funct()
const {return rep.hash_funct(); }

key_equel key_eq()
const { return rep.key_eq(); }

public:

//各种构造函数 ,不给定大小的话默认值为100,实际上找到的质数为193

hash_map() : rep(, hasher(), key_equel()){}

explicit hash_map(size_type n) : rep(n, hasher(), key_equel()) {}

hash_map(size_type n,
const hasher& hf) : rep(n, hf, key_equel()) {}

hash_map(size_type n,
const hasher& hf,
const key_equel& eql)

: rep(n, hf, eql) {}

template< class InputIterator>

hash_map(InputIterator f, InputIterator l)

: rep(, hasher(), key_equel()) { rep.insert_unique(f, l); }

template< class InputIterator>

hash_map(InputIterator f, InputIterator l, size_type n)

: rep(n, hasher(), key_equel()) { rep.insert_unique(f, l); }

template< class InputIterator>

hash_map(InputIterator f, InputIterator l, size_type n,
const hasher& hf)

: rep(n, hf, key_equel()) { rep.insert_unique(f, l); }

template< class InputIterator>

hash_map(InputIterator f, InputIterator l, size_type n,
const hasher& hf

const key_equel& eql)

: rep(, hf, eql) { rep.insert_unique(f, l); }

public:

size_type size()
const {return rep.size();}

size_type max_size()
const { return rep.max_size(); }

bool empty() const {return rep.empty(); }

void swap(hash_map& hs) { rep.swap(hs.rep); }

friend bool
operator== __STL_NULL_TMPL_ARGS (const hash_map&,
const hash_map&);

iterator begin()
const { return rep.begin(); }

iterator end()
const { return rep.end(); }

public:

pair<iterator,
bool> insert(const value_type& obj)

{

//之前在set中就想过
为什么不直接返回 在map中看到时直接返回了,

//不是像set中一样还要先申请一个临时变量
再返回临时变量

//经过一番努力,发现:set的iterator是const_iterator,因为set不能更改值嘛

//所以需要进行转化,所以set那里会复杂一些

return rep.insert_unique(obj);

}

template<class InputIterator>

void insert(InputIterator f, InputIterator l) { rep.insert_unique(f,l); }

pair<iterator,
bool> insert_noresize(const value_type& obj)

{

return  rep.insert_unique_noresize(obj);

}

iterator find(const key_type& key)
const { return rep.find(key); }

const_iterator find(const key_type& key)
const { return rep.find(key);}

T&
operator[](const key_type& key)

{

return rep.find_or_insert(value_type(key, T())).second;

}

size_type count(const key_type& key)
const {return rep.count(key); }

//相等的key的位置(是一个左闭右开的区间),由迭代器给出

pair<iterator, iterator> equal_range(const key_type& key)
const

{
return rep.equal_range(key); }

size_type erase(const key_type& key) {
return rep.erase(key); }

void erase(iterator it) { rep.erase(it); }

void erase(iterator f, iterator l) { rep.erase(f, l); }

void clear() { rep.clear(); }

public:

void    resize(size_type hint) { rep.resize(hint); }

size_type bucket_count()
const { return rep.bucket_count(); }

size_type elems_in_bucket(size_type n)
const

{
return rep.elems_in_bucket(n); }

//class

template<class Value,
class HashFcn, class EqualKey,
class Alloc>

inline bool
operator==(const hash_map<Value, HashFcn, EqualKey, Alloc>& hm1,

const hash_map<Value, HashFcn, EqualKey, Alloc>& hm2)

{

return has1.rep == has2.rep;

}

};

}

//hash_multiset

{

/*

hash_multiset概述:

同上

*/

//class

template<class Value,
class HashFcn = hash<Value>,

class EqualKey = equal_to<Value>,
class Alloc=alloc>

class hash_multiset

{

private:

typedef hash_multiset<Value, Value, HashFcn, identity<Value>,

EqualKey, Alloc> ht;

ht rep;

public:

typedef typename ht::key_type key_type;

typedef typename ht::value_type value_type;

typedef typename ht::hasher hasher;        
//hashtable中: typedef HashFcn hasher

typedef typename ht::key_equel key_equel;

typedef typename ht::size_type size_type;

typedef typename ht::difference_type difference_type;

typedef typename ht::const_pointer pointer;

typedef typename ht::const_pointer const_pointer;

typedef typename ht::const_reference reference;

typedef typename ht::const_reference const_reference;

typedef typename ht::const_iterator iterator;

typedef typename ht::const_iterator const_iterator;

hasher hash_funct()
const {return rep.hash_funct(); }

key_equel key_eq()
const { return rep.key_eq(); }

public:

//各种构造函数 ,不给定大小的话默认值为100,实际上找到的质数为193

hash_multiset() : rep(100,hasher(), key_equel()){}

explicit hash_multiset(size_type n) : rep(n, hasher(), key_equel()) {}

hash_multiset(size_type n,
const hasher& hf) : rep(n, hf, key_equel()) {}

hash_multiset(size_type n,
const hasher& hf,
const key_equel& eql)

: rep(n, hf, eql) {}

template< class InputIterator>

hash_multiset(InputIterator f, InputIterator l)

: rep(, hasher(), key_equel()) { rep.insert_equal(f, l); }

template< class InputIterator>

hash_multiset(InputIterator f, InputIterator l, size_type n)

: rep(n, hasher(), key_equel()) { rep.insert_equal(f, l); }

template< class InputIterator>

hash_multiset(InputIterator f, InputIterator l, size_type n,
const hasher& hf)

: rep(n, hf, key_equel()) { rep.insert_equal(f, l); }

template< class InputIterator>

hash_multiset(InputIterator f, InputIterator l, size_type n,
const hasher& hf

const key_equel& eql)

: rep(, hf, eql) { rep.insert_equal(f, l); }

public:

size_type size()
const {return rep.size();}

size_type max_size()
const { return rep.max_size(); }

bool empty() const {return rep.empty(); }

void swap(hash_multiset& hs) { rep.swap(hs.rep); }

friend bool
operator== __STL_NULL_TMPL_ARGS (const hash_multiset&,
const hash_multiset&);

iterator begin()
const { return rep.begin(); }

iterator end()
const { return rep.end(); }

public:

iterator insert(const value_type& obj)

{

return rep.insert_equal(obj);

}

template<class InputIterator>

void insert(InputIterator f, InputIterator l) { rep.insert_equal(f,l); }

iterator insert_noresize(const value_type& obj)

{

return rep.insert_equal_noresize(obj);

}

iterator find(const key_type& key)
const { return rep.find(key); }

size_type count(const key_type& key)
const {return rep.count(key); }

//相等的key的位置(是一个左闭右开的区间),由迭代器给出

pair<iterator, iterator> equal_range(const key_type& key)
const

{
return rep.equal_range(key); }

size_type erase(const key_type& key) {
return rep.erase(key); }

void erase(iterator it) { rep.erase(it); }

void erase(iterator f, iterator l) { rep.erase(f, l); }

void clear() { rep.clear(); }

public:

void    resize(size_type hint) { rep.resize(hint); }

size_type bucket_count()
const { return rep.bucket_count(); }

size_type elems_in_bucket(size_type n)
const

{
return rep.elems_in_bucket(n); }

//class

template<class Value,
class HashFcn, class EqualKey,
class Alloc>

inline bool
operator==(const hash_multiset<Value, HashFcn, EqualKey, Alloc>& hs1,

const hash_multiset<Value, HashFcn, EqualKey, Alloc>& hs2)

{

return has1.rep == has2.rep;

}

};

}

//hash_multimap

{

/*

hash_multimap概述:

同上

*/

//class

template<class Key,
class T, class HashFcn = hash<Value>,

class EqualKey = equal_to<Value>,
class Alloc=alloc>

class hash_multimap

{

private:

typedef hashtable<pair<const Key, T>, Key, HashFcn,

select1st<pair<const Key, T>, EqualKey, Alloc> ht;

ht rep;

public:

typedef typename ht::key_type key_type;

typedef T data_type;

typedef T mapped_type;

typedef typename ht::value_type value_type;

typedef typename ht::hasher hasher;        
//hashtable中: typedef HashFcn hasher

typedef typename ht::key_equel key_equel;

typedef typename ht::size_type size_type;

typedef typename ht::difference_type difference_type;

typedef typename ht::pointer pointer;

typedef typename ht::const_pointer const_pointer;

typedef typename ht::reference reference;

typedef typename ht::const_reference const_reference;

typedef typename ht::iterator iterator;

typedef typename ht::const_iterator const_iterator;

hasher hash_funct()
const {return rep.hash_funct(); }

key_equel key_eq()
const { return rep.key_eq(); }

public:

//各种构造函数 ,不给定大小的话默认值为100,实际上找到的质数为193

hash_multimap() : rep(, hasher(), key_equel()){}

explicit hash_multimap(size_type n) : rep(n, hasher(), key_equel()) {}

hash_multimap(size_type n,
const hasher& hf) : rep(n, hf, key_equel()) {}

hash_multimap(size_type n,
const hasher& hf,
const key_equel& eql)

: rep(n, hf, eql) {}

template< class InputIterator>

hash_multimap(InputIterator f, InputIterator l)

: rep(, hasher(), key_equel()) { rep.insert_equal(f, l); }

template< class InputIterator>

hash_multimap(InputIterator f, InputIterator l, size_type n)

: rep(n, hasher(), key_equel()) { rep.insert_equal(f, l); }

template< class InputIterator>

hash_multimap(InputIterator f, InputIterator l, size_type n,
const hasher& hf)

: rep(n, hf, key_equel()) { rep.insert_equal(f, l); }

template< class InputIterator>

hash_multimap(InputIterator f, InputIterator l, size_type n,
const hasher& hf

const key_equel& eql)

: rep(, hf, eql) { rep.insert_equal(f, l); }

public:

size_type size()
const {return rep.size();}

size_type max_size()
const { return rep.max_size(); }

bool empty() const {return rep.empty(); }

void swap(hash_multimap& hs) { rep.swap(hs.rep); }

friend bool
operator== __STL_NULL_TMPL_ARGS (const hash_multimap&,
const hash_multimap&);

iterator begin()
const { return rep.begin(); }

iterator end()
const { return rep.end(); }

public:

iterator insert(const value_type& obj)

{

return rep.insert_equal(obj);

}

template<class InputIterator>

void insert(InputIterator f, InputIterator l) { rep.insert_equal(f,l); }

iterator insert_noresize(const value_type& obj)

{

return  rep.insert_equal_noresize(obj);

}

iterator find(const key_type& key)
const { return rep.find(key); }

const_iterator find(const key_type& key)
const { return rep.find(key);}

size_type count(const key_type& key)
const {return rep.count(key); }

//相等的key的位置(是一个左闭右开的区间),由迭代器给出

pair<iterator, iterator> equal_range(const key_type& key)
const

{
return rep.equal_range(key); }

size_type erase(const key_type& key) {
return rep.erase(key); }

void erase(iterator it) { rep.erase(it); }

void erase(iterator f, iterator l) { rep.erase(f, l); }

void clear() { rep.clear(); }

public:

void    resize(size_type hint) { rep.resize(hint); }

size_type bucket_count()
const { return rep.bucket_count(); }

size_type elems_in_bucket(size_type n)
const

{
return rep.elems_in_bucket(n); }

//class

template<class Value,
class HashFcn, class EqualKey,
class Alloc>

inline bool
operator==(const hash_multimap<Value, HashFcn, EqualKey, Alloc>& hm1,

const hash_multimap<Value, HashFcn, EqualKey, Alloc>& hm2)

{

return has1.rep == has2.rep;

}

};

}

stl源码剖析 详细学习笔记 hashset hashmap的更多相关文章

  1. stl源码剖析 详细学习笔记 hashtable

    //---------------------------15/03/24---------------------------- //hashtable { /* 概述: sgi采用的是开链法完成h ...

  2. stl源码剖析 详细学习笔记 set map

    // //  set map.cpp //  笔记 // //  Created by fam on 15/3/23. // // //---------------------------15/03 ...

  3. stl源码剖析 详细学习笔记 RB_tree (1)

    // //  RB_tree_STL.cpp //  笔记 // //  Created by fam on 15/3/21. // // #include "RB_tree_STL.h&q ...

  4. stl源码剖析 详细学习笔记heap

    // //  heap.cpp //  笔记 // //  Created by fam on 15/3/15. // // //---------------------------15/03/15 ...

  5. stl源码剖析 详细学习笔记 空间配置器

    //---------------------------15/04/05---------------------------- /* 空间配置器概述: 1:new操作包含两个阶段操作 1>调 ...

  6. stl源码剖析 详细学习笔记 算法(1)

    //---------------------------15/03/27---------------------------- //算法 { /* 质变算法:会改变操作对象之值 所有的stl算法都 ...

  7. stl源码剖析 详细学习笔记 算法总览

    //****************************基本算法***************************** /* stl算法总览,不在stl标准规格的sgi专属算法,都以 *加以标 ...

  8. stl源码剖析 详细学习笔记 RB_tree (2)

    //---------------------------15/03/22---------------------------- //一直好奇KeyOfValue是什么,查了下就是一个和仿函数差不多 ...

  9. stl源码剖析 详细学习笔记priority_queue slist

    // //  priority_queue.cpp //  笔记 // //  Created by fam on 15/3/16. // // //------------------------- ...

随机推荐

  1. "添加"模态框中某些数据不被清空

    描述:一般情况下,“添加”的模态框弹出够,其中的输入框等为空,若是此中有某些数据是取自其他页面,不应被清空的,我们应当在html中添加以下内容.   解决方案:在form标签中添加“ preserve ...

  2. 中断标志位 IRQF_ONESHOT

    one shot本身的意思的只有一次的,结合到中断这个场景,则表示中断是一次性触发的,不能嵌套.对于primary handler,当然是不会嵌套,但是对于threaded interrupt han ...

  3. Unity By Reflection Update Scripts

    App热更新需求 我正在使用Unity 3D开发一个Android的应用,它会下载AssetBundles并加载它们的内容,但由于AssetBundles不能包含脚本,我将使用预编译的C#脚本,并使用 ...

  4. 汇编语言debug命令与指令机器码

    一.debug命令 二.标志信息 -r用这个指令,得到的信息右下角: NV UP EI PL NZ NA PO NC 这些符号代表的就是标志寄存器里常用标志位的值.这个是符号值对应表: 溢出标志OF( ...

  5. 新人如何进入IT行业

    你遇到了我刚毕业时遇到的问题. 现在需要知道你希望在那里就业,上海和北京就业的待遇差不多,北京能比上海稍微少点(我是指你这类刚毕业的) 说主题好了 应届毕业,找工作都很难的,因为现在很多企业是不愿意找 ...

  6. Matlab feval函数(转)

    http://zhidao.baidu.com/link?url=7CusQYQXhCDB8sUtolMEhI1ctnpblbYrpSnU0fhIh5LvDZuhsBuozQusS6Kb1McTp7x ...

  7. Linux运维之——每日小技巧,使用awk命令截取每行的指定列数据

    获取/etc/passwd目录下的UID值小于10的数,并输出第一.三列 [root@:vg_adn_tidbCkhsTest:172.31.30.62 ~]#cat /etc/passwd | aw ...

  8. Monad、Actor与并发编程--基于线程与基于事件的并发编程之争

    将线程.事件.状态等包装成流的源. 核心:解决线程的消耗和锁的效率问题. Java和Node.js可以说分别是基于线程和基于事件的两个并发编程代表,它们互相指责瞧不起对方,让我们看看各种阵营的声音: ...

  9. Mapreduce运行过程分析(基于Hadoop2.4)——(二)

    4.3 Map类    创建Map类和map函数.map函数是org.apache.hadoop.mapreduce.Mapper类中的定义的,当处理每一个键值对的时候,都要调用一次map方法,用户须 ...

  10. Redis系列六:redis相关功能

    一. 慢查询原因分析 与mysql一样:当执行时间超过阀值,会将发生时间耗时的命令记录 redis命令生命周期:发送 排队 执行 返回慢查询只统计第3个执行步骤的时间 预设阀值:两种方式,默认为10毫 ...