Skip to content

Setting individual chances in Chances has inconsistent behavior #93

@Samasaur1

Description

@Samasaur1

Here's the getter/setter for what I'm talking about.

public subscript(of roll: Roll) -> Chance {
get {
return chances[roll] ?? Chance.zero
}
set {
chances[roll] = newValue
}
}

As you can see, when getting a Chance, the assumption is that if it is not there, it's zero. That's what we want. However, when we set a chance to zero, we add it to the dictionary, potentially resulting in a large number of entries with Chance.zero as their values. This is unnecessary, could potentially be detrimental (storage space), and is internally inconsistent. I think it doesn't actually have an outward-facing effect, because we filter out chances that are not greater than zero:
for (roll, chance) in chances where chance.n > 0 {

but we could and probably should still change this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions