[GiNaC-devel] Erasing-inserting exhashmap
Richard B. Kreckel
kreckel at in.terlu.de
Sun Sep 22 02:08:36 CEST 2019
Dear Vladimir,
On 19.09.19 17:06, Vladimir V. Kisil wrote:
> I have an issue with exhashmap, namely repeated
> erasing-insertion of elements eventually become trapped in an infinite
> loop in lines 487-491 of hash_map.h. Here is a sample code:
>
> #include <ginac/ginac.h>
> using namespace GiNaC;
>
> int main()
> {
> exhashmap<ex> M;
>
> M[realsymbol("x")] =1;
> int N= 30;
>
> for (int i =0; i < N; ++i ) {
> realsymbol a("a");
> M[a]=numeric(i);
> M.erase(a);
> }
> return 0;
> }
>
> With this value of N the infinite loop appears on my computer with a
> probability around 40%. With larger values of N an infinite loop is
> almost certain.
>
> Did I miss something?
Class exhashmap<T> was a workaround for missing std::hash_map<Key, T> in
the original C++98 standard. It was put in GiNaC because map<Key, T> was
deemed too slow. Since C++11 there is std::unorderd_map<Key, T>, which
is hash-based.
Don't use that exhashmap. It should have been replaced years ago when we
switched to C++11!
The attached prelimiary patch should solve all these problems. Can you,
please, test it with whatever you're doing?
> PS Also just to check that my patch for archiving empty lists from Sep
> 10 is not lost.
Worry not!
-richy.
--
Richard B. Kreckel
<https://in.terlu.de/~kreckel/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: exhashmap.patch
Type: text/x-patch
Size: 17073 bytes
Desc: not available
URL: <http://www.ginac.de/pipermail/ginac-devel/attachments/20190922/1009025f/attachment.bin>
More information about the GiNaC-devel
mailing list