fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

Is `abstract_array.length` needed when we have `count` already?

Open michaellilltokiwa opened this issue 3 months ago • 3 comments

My hunch currently is that we should just drop length

michaellilltokiwa avatar Sep 10 '25 10:09 michaellilltokiwa

Nope. Semantically, they both return the length. The difference is that length guarantees to be in O(1) while count might be in O(result). So, whenever you see count, alarm bells should ring!

What is missing is better documentation of these complexities.

fridis avatar Sep 23 '25 14:09 fridis

@fridis Okay, but one could argue that if finite = finite.yes then count is also guaranteed to be O(1)

michaellilltokiwa avatar Oct 06 '25 09:10 michaellilltokiwa

@fridis Okay, but one could argue that if finite = finite.yes then count is also guaranteed to be O(1)

For a Sequence, this is not the case, we can very well imagine a Sequence that is finite but that does not store the count explicitly but performs O(count) counting on every call to count.

fridis avatar Oct 06 '25 10:10 fridis