EMSI Containers and HashMap of HashMaps

Tobias Pankrath tobias+dlang at pankrath.net
Sun May 2 07:38:03 UTC 2021


The following code segfaults, when the outer hashmap rehashes,
and I am not yet sure why.

```d
module tests.refcounted_hashmap_test;

import containers;
import std.typecons;

struct Map
{
     HashMap!(int, int) theMap;
}

unittest
{
     HashMap!(int, RefCounted!Map) mapOfMaps;
     foreach (i; 0 .. 1000)
     {
         RefCounted!Map val;
         if (i == 0) val.theMap.getOrAdd(i, i);
         mapOfMaps.getOrAdd(i, val);
     }
}
```

For your convenience: https://run.dlang.io/is/gHSlu1

I am using Refcounted() because HashMap itself is not copy-able. 
Is there another way to have HashMaps as values of HashMaps?




More information about the Digitalmars-d-learn mailing list