-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.cpp
More file actions
58 lines (51 loc) · 1.28 KB
/
hash.cpp
File metadata and controls
58 lines (51 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <boost/functional/hash.hpp>
#include <boost/unordered_set.hpp>
#include <boost/foreach.hpp>
#include <string>
using namespace std;
namespace lib{
struct book
{
int id;
string author;
string title;
book(int _id, string _author, string _title)
{
id = _id;
author = _author;
title = _title;
}
};
bool operator==(const book& a, const book& b)
{
return a.id == b.id;
}
std::size_t hash_value(book const&a)
{
boost::hash<int>hasher;
return hasher(a.id);
}
}
int main()
{
boost::hash<string> string_hash;
cout << string_hash("WO CAO") << endl;
boost::hash< vector<int> > vector_hash;
int a[3] = {2,3,1};
vector<int>v(a, a + 3);
cout << vector_hash(v) << endl;
lib::book knife(3458, "Zane Grey", "The Hash Knife Outfit");
lib::book danger(1354, "Paul J. Shanley", "HAHAHAHAHAH");
boost::hash< lib::book >hasher;
cout << hasher(knife) << "\t" << hasher(danger) << endl;
boost::unordered_set< lib::book > oset;
oset.insert(knife);
oset.insert(danger);
oset.insert(lib::book(123, "London", "Strong Man"));
BOOST_FOREACH(lib::book book, oset)
{
cout << book.id << "\t" << book.author << "\t" << book.title << endl;
}
return 0;
}