@@ -18,19 +18,18 @@ size_t irep_hash_container_baset::number(const irept &irep)
18
18
{
19
19
// the ptr-hash provides a speedup of up to 3x
20
20
21
- ptr_hasht::const_iterator it=ptr_hash.find (&irep.read ());
21
+ auto entry = ptr_hash.emplace (
22
+ std::piecewise_construct,
23
+ std::forward_as_tuple (&irep.read ()),
24
+ std::forward_as_tuple (0 , irep));
22
25
23
- if (it!=ptr_hash. end () )
24
- return it ->second .number ;
26
+ if (!entry. second && entry. first -> second . final_number )
27
+ return entry. first ->second .number ;
25
28
26
- packedt packed;
27
- pack (irep, packed);
28
- size_t id=numbering.number (packed);
29
+ const size_t id = numbering.number (pack (irep));
29
30
30
- ptr_hash.emplace (
31
- std::piecewise_construct,
32
- std::forward_as_tuple (&irep.read ()),
33
- std::forward_as_tuple (id, irep));
31
+ entry.first ->second .number = id;
32
+ entry.first ->second .final_number = true ;
34
33
35
34
return id;
36
35
}
@@ -44,9 +43,7 @@ size_t irep_hash_container_baset::vector_hasht::operator()(
44
43
return result;
45
44
}
46
45
47
- void irep_hash_container_baset::pack (
48
- const irept &irep,
49
- packedt &packed)
46
+ irep_hash_container_baset::packedt irep_hash_container_baset::pack (const irept &irep)
50
47
{
51
48
const irept::subt &sub=irep.get_sub ();
52
49
const irept::named_subt &named_sub=irep.get_named_sub ();
@@ -61,7 +58,7 @@ void irep_hash_container_baset::pack(
61
58
#else
62
59
const std::size_t named_sub_size = named_sub.size ();
63
60
#endif
64
- packed. reserve (1 + 1 + sub.size () + 1 + named_sub_size * 2 );
61
+ packedt packed (1 + 1 + sub.size () + 1 + named_sub_size * 2 );
65
62
66
63
packed.push_back (irep_id_hash ()(irep.id ()));
67
64
@@ -75,6 +72,8 @@ void irep_hash_container_baset::pack(
75
72
packed.push_back (irep_id_hash ()(sub_irep.first )); // id
76
73
packed.push_back (number (sub_irep.second )); // sub-irep
77
74
}
75
+
76
+ return packed;
78
77
}
79
78
else
80
79
{
@@ -83,7 +82,7 @@ void irep_hash_container_baset::pack(
83
82
84
83
// we pack: the irep id, the sub size, the subs, the named-sub size, and
85
84
// each of the non-comment named subs with their ids
86
- packed. reserve (1 + 1 + sub.size () + 1 + non_comment_count * 2 );
85
+ packedt packed (1 + 1 + sub.size () + 1 + non_comment_count * 2 );
87
86
88
87
packed.push_back (irep_id_hash ()(irep.id ()));
89
88
@@ -98,5 +97,7 @@ void irep_hash_container_baset::pack(
98
97
packed.push_back (irep_id_hash ()(sub_irep.first )); // id
99
98
packed.push_back (number (sub_irep.second )); // sub-irep
100
99
}
100
+
101
+ return packed;
101
102
}
102
103
}
0 commit comments