-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.cpp
64 lines (49 loc) · 2.09 KB
/
example.cpp
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
59
60
61
62
63
64
/**
Copyright 2015 Steve Göring
haesni example program
\author stg7
\brief small demonstration of haesni usage
\date 15.11.2015
**/
/**
This file is part of haesni.
haesni is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
haesni is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with haesni. If not, see <http://www.gnu.org/licenses/>.
**/
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include "haesni.hpp"
int main(int argc, const char* argv[]) {
std::cout << "small demo for haesni" << std::endl;
std::vector<std::string> hash_strings { "hello", "hello world", "world", "haesni", "haesni is fast" };
for (auto& str : hash_strings) {
std::cout << "haesni(\"" << str << "\") = "
<< haesni::hash(&str[0], str.length()) << std::endl;
}
std::cout << "static tests:" << std::endl;
{
std::string s1 = "pppppppppp aaaaaaaaaa wwwwwwwwwwwwwwwww ssssssssssssssssssssss fffffffffff";
std::string s2 = "pppppppppp aaaaaaaaaa wwwwwwwwwwwwwwwww ssssssssssssssssssssss fffffffffff";
std::cout << " equal hash: ";
assert(haesni::hash(&s1[0], s1.length()) == haesni::hash(&s2[0], s2.length()));
std::cout << "done." << std::endl;
}
{
std::string s1 = "pppppppppp aaaaaaaaaa wwwwwwwwwwwwwwwww ssssssssssssssssssssss fffffffffff";
std::string s2 = "pppppppppp aaaaaaaaaa wwwwwwwwwwwwwwwww ssssssssssssssssssssss fffffffffffsss";
std::cout << " unequal hash: ";
assert(haesni::hash(&s1[0], s1.length()) != haesni::hash(&s2[0], s2.length()));
std::cout << "done." << std::endl;
}
return 0;
}