C++ Container equivalents

Bruce Adams tortoise_74 at nospam.ya.hoo.co.mapson.uk
Wed Aug 15 16:16:26 PDT 2007


Deewiant Wrote:

> Sean Kelly wrote:
> > Tango has a module containing array algorithms in tango.core.Array.
> > Unlike the C++ spec however, algorithm complexity is stated in plain
> > language rather than in big-O terms.  find(), for example, "performs a
> > "linear scan of buf from [0 .. buf.length)," which implies that it has
> > O(N) complexity.
> > 
> 
> It might be worth it adding the big O notation anyway: if you know what it
> means, it's quicker to scan for and interpret than a full-sentence explanation.
> 
> -- 
> Remove ".doesnotlike.spam" from the mail address.

Off topic but what I'd love to see is complexity constraints.
Something like:

void function(int[] array)
{
   invariant {
      static assert(complexity(thisFunc) == constantTime);
   }
   foreach(x; array) {   // contraint failed - foreach implies O(n)
   }
}

In practice a compiler could only work out some simple cases
of complexity constraint violation but even where it can't the
assertion provides useful documentation.


More information about the Digitalmars-d-learn mailing list