Complexity nomenclature

Jakob Ovrum via Digitalmars-d digitalmars-d at puremagic.com
Fri Dec 4 00:41:41 PST 2015


On Friday, 4 December 2015 at 06:05:55 UTC, Tofu Ninja wrote:
> When would a generic algorithm even need to know the complexity 
> of the container?

A generic algorithm that uses exponential time when given the 
"wrong" inputs is a hidden danger. This can easily happen when 
composing with linear algorithms. This naming scheme, also 
employed by std.container, prevents this.

> Also maybe a simpler idea would just be to annotate the the 
> operations with there complexity with UDAs. That way things 
> that really care about the complexity can get it, and those who 
> don't can ignore it. It has the benefit of being self 
> documenting as well.

If you don't care about the complexity, why are you using 
collections? Just use T[] and T[U]. Surely choosing a data 
structure is all about complexity (barring some details like 
optimizing for cache locality or small data structures).




More information about the Digitalmars-d mailing list