Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax question: Idiomatic histograms #57

Open
rsaarelm opened this issue Mar 14, 2024 · 1 comment
Open

Syntax question: Idiomatic histograms #57

rsaarelm opened this issue Mar 14, 2024 · 1 comment

Comments

@rsaarelm
Copy link

rsaarelm commented Mar 14, 2024

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.

@FeepingCreature
Copy link
Contributor

It should work like that. TODO...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants