array cast should be supported corrected

BCS ao at pathlink.com
Wed Aug 6 14:38:22 PDT 2008


Reply to Bill,

> On Thu, Aug 7, 2008 at 6:06 AM, BCS <ao at pathlink.com> wrote:
> 
>> Reply to Frank,
>> 
>>> However. What is better in a template arraycast with o(n) or a cast?
>>> The programmer always needs to know what the concequences are. With
>>> this argumentation the string concatenation ~ should also be banned
>>> from
>>> the language, because hidden heap allocation has always unbound
>>> execution
>>> time.
>> Array cat's /always/ do a O(?) allocation and a O(n+m) copy.
>> 
> Not true for ~=.  Sometimes allocates sometimes doesn't.  You'll have
> to come up with a better argument than that. :-)
> 

http://www.digitalmars.com/d/1.0/arrays.html
"Concatenation always creates a copy of its operands"

http://www.digitalmars.com/d/1.0/expression.html
""
Assignment operator expressions, such as:  a op= b
are semantically equivalent to:  a = a op b
""

>> Cast usually
>> does a O(1) transformation. Having the corner case be much worse than
>> the
>> normal case is the problem, not the fact it's O(n).
> I think casting to an interface is O(n) in the number of interfaces
> the object supports, no?

I think that it's just a simple addition as the interface vtbl in a given 
class is at a constant offset from the base of the object. I don't /think/ 
a class to interface cast can fail at run time. OTOH casting from an interface 
to a base class of the actual type... I haven't a clue what that's doing. 
Might be O(n) on the number of derivations

The O(n) I was looking at would be on the length of the array.

> 
> --bb
> 





More information about the Digitalmars-d mailing list