You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to make a two-layer histogram structure that accumulates values in bins. Naively, I'd try writing it like this:
struct LogEntry { string day; string task; long duration; }
mut long[string][string] layeredHistogram;
for (entry in log) // input values from outside the example
layeredHistogram[entry.day][entry.task] += entry.duration; // Haha, nope
print("$layeredHistogram");
This doesn't currently work. Should it be made to work or is there a better way to write this idiomatically?
Specifically, there's the expectation of default values here. When a key isn't present in a long valued hashmap, histogram logic expects to pull a 0 (default value for the type) for it. See eg. defaultdict in Python.
The text was updated successfully, but these errors were encountered:
I want to make a two-layer histogram structure that accumulates values in bins. Naively, I'd try writing it like this:
This doesn't currently work. Should it be made to work or is there a better way to write this idiomatically?
Specifically, there's the expectation of default values here. When a key isn't present in a
long
valued hashmap, histogram logic expects to pull a 0 (default value for the type) for it. See eg. defaultdict in Python.The text was updated successfully, but these errors were encountered: