Complexity nomenclature

tn via Digitalmars-d digitalmars-d at puremagic.com
Fri Dec 4 06:50:07 PST 2015


On Friday, 4 December 2015 at 09:57:48 UTC, Jakob Ovrum wrote:
> On Friday, 4 December 2015 at 09:51:05 UTC, tn wrote:
>> "I just want to insert an element. I don't care how long it 
>> takes. Why do I need to specify that it should be linear?"
>>
>> In my opinion, there should be "constantInsert", 
>> "linearInsert", etc. for those who care about the complexity, 
>> and "insert" should be always available.
>
> In the current std.container, linearInsert aliases to the 
> sublinear insert function when it's provided. If you don't care 
> about running time, just use linearInsert.

I understand this.

However, my point is that it seems backwards if
1) When I don't care about the complexity, then I need to specify 
one (e.g. linearInsert).
2) When I care and want a constant complexity, then I don't 
specify one (e.g. use insert instead of constantInsert).

In addition, if a new container is added that only provides O(n 
log n) insert, then my "don't care" code that uses linearInsert 
does not support the new container without changes.



More information about the Digitalmars-d mailing list