A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
hash-example.cc File Reference

Example usage of ns3::Hash. More...

#include "ns3/core-module.h"
#include "ns3/hash.h"
#include <algorithm>
#include <climits>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
+ Include dependency graph for hash-example.cc:

Go to the source code of this file.

Classes

class  ns3::Hash::Example::Collider
 Keep track of collisions. More...
 
class  ns3::Hash::Example::DictFiles
 Source word list files. More...
 
class  ns3::Hash::Example::Dictionary
 Word list and hashers to test. More...
 

Namespaces

namespace  ns3
 Every class exported by the ns3 library is enclosed in the ns3 namespace.
 
namespace  ns3::Hash
 Hash function implementations.
 
namespace  ns3::Hash::Example
 Namespace for hasher-example.
 

Detailed Description

Example usage of ns3::Hash.

This example reads words from a list of files, creates a dictionary mapping words to hash values, reports collisions, and measures the execution time of the hash function implementations.

See Hash Functions

Example Output:

./ns3 run "hasher-example --time \
  --dict=/usr/share/dict/web2 \
  --dict=/usr/share/dict/web2a \
  --dict=/usr/share/dict/propernames \
  --dict=/usr/share/dict/connectives"

'build' finished successfully (3.028s)

Hasher
Hashing the dictionaries
Dictionary file: /usr/share/dict/web2
Dictionary file: /usr/share/dict/web2a
Dictionary file: /usr/share/dict/propernames
Dictionary file: /usr/share/dict/connectives

Number of words or phrases: 312094
Expected number of collisions: (32-bit table) 11.3389
Expected number of collisions: (64-bit table) 2.6401e-09

FNV1a (32-bit version): 13 collisions:
a75b0ae7  elephantlike        interventralia
091c4808  diversionary        propenseness
172be6ba  bairnishness        sora
e6cb5099  purifier            spongoblastic
4a841078  ameliorable         unsmotherable
6ed21de2  brand-newness       peripherial
22acb19b  Petrarchism         dewy-pinioned
5723634a  grain gold          hyphenation
f58026c1  seven-channeled     turritella
946fc6ec  multiradiate        sister block
88625851  brachtmema          ule tree
dc28b5ea  Un-lutheran         gutturotetany
9255bf44  re-sorter           working stress

FNV1a (64-bit version): 0 collisions:

Murmur3 (32-bit version): 11 collisions:
5ea83eee  impalace            metahewettite
e06fbdde  constancy           oligosynthetic
2a713795  hypermonosyllable   presatisfaction
c8bf0ef9  Hadromerina         starky
d9c04b3d  Accipiter           syllable
c0da8f81  seriation           trigonon
17612b26  daemon              unerring
c2349ad7  air spring          iron
1d91386f  nine-pounder        semicrescentic
fe17b1a5  cone speaker        oblong-wedgeshaped
faa12798  saw bearing         wilting point

Murmur3 (64-bit version): 0 collisions:

Hash timing                        Phrases      Reps     Ticks     ns/hash
FNV1a (32-bit version)              312094       100   3140531     100.628
FNV1a (64-bit version)              312094       100   3145240     100.779
Murmur3 (32-bit version)            312094       100   4152139     133.041
Murmur3 (64-bit version)            312094       100   4191464     134.301

Definition in file hash-example.cc.