Skip to content

[Suggestion] mögliche Verbesserung der Implementation von UrnOR::next() #9

Description

@arrrrrrrrrrrrrr

What could be improved?

Die Implementation von UrnOR::next() kommt mir ein bisschen umständlich/ineffizient vor. Im worst case läuft sie in O(n^2), während ich denke, dass O(n) möglich ist (siehe Vorschlag).
LG!

Do you have a suggestion on how to improve it?

bool UrnOR::next() 
{
	uint down { m_k };
	
	while (down > 1 && m_balls[down-1] == m_n-1) 
	{
		m_balls[down-1] = 0;
		down--;
	}
	if (down > 0 && m_balls[down-1] < m_n-1) 
	{
		m_balls[down-1]++;
		return true;
	}
	return false;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions