-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringset.cc
45 lines (38 loc) · 1.46 KB
/
stringset.cc
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
#include <string>
#include <unordered_set>
using namespace std;
#include "stringset.h"
typedef unordered_set<string> stringset;
typedef stringset::const_iterator stringset_citor;
typedef stringset::const_local_iterator stringset_bucket_citor;
stringset set;
stringset set_internal;
const string* intern_stringset (const char* string, bool no_insert) {
if (no_insert) {
pair<stringset_citor,bool> handle = set_internal.insert (string);
return &*handle.first;
} else {
pair<stringset_citor,bool> handle = set.insert (string);
return &*handle.first;
}
}
void dump_stringset (FILE* out) {
size_t max_bucket_size = 0;
for (size_t bucket = 0; bucket < set.bucket_count(); ++bucket) {
bool need_index = true;
size_t curr_size = set.bucket_size (bucket);
if (max_bucket_size < curr_size) max_bucket_size = curr_size;
for (stringset_bucket_citor itor = set.cbegin (bucket);
itor != set.cend (bucket); ++itor) {
if (need_index) fprintf (out, "stringset[%4lu]: ", bucket);
else fprintf (out, " %4s ", "");
need_index = false;
const string* str = &*itor;
fprintf (out, "%22lu %p->\"%s\"\n", set.hash_function()(*str),
str, str->c_str());
}
}
fprintf (out, "load_factor = %.3f\n", set.load_factor());
fprintf (out, "bucket_count = %lu\n", set.bucket_count());
fprintf (out, "max_bucket_size = %lu\n", max_bucket_size);
}