1. Quickest way to find out if a sequence is/isn't empty?

What would be the quickest way to verify if a sequence is/isn't empty? This especially applies to sequences of considerable sizes.

What I'm trying to explain, is that if a sequence contains data, I don't want the code to iterate through the whole sequence to verify that it ISN'T empty.. I'm guessing not length(mySequence) (or length(mySequence)=0) wouldn't be the quickest one, as it would presumably count through the whole sequence and THEN find out that it isn't empty.

I've also used equal({}, mySequence), but I'm kind of guessing that that also would run through the whole sequence before finding out that it isn't empty.

Regards, ZNorQ aka Kenneth

new topic     » topic index » view message » categorize

2. Re: Quickest way to find out if a sequence is/isn't empty?

ZNorQ said...

What would be the quickest way to verify if a sequence is/isn't empty? This especially applies to sequences of considerable sizes.

What I'm trying to explain, is that if a sequence contains data, I don't want the code to iterate through the whole sequence to verify that it ISN'T empty.. I'm guessing not length(mySequence) (or length(mySequence)=0) wouldn't be the quickest one, as it would presumably count through the whole sequence and THEN find out that it isn't empty.

I've also used equal({}, mySequence), but I'm kind of guessing that that also would run through the whole sequence before finding out that it isn't empty.

Regards, ZNorQ aka Kenneth

length(mySequence) is the fastest. length() doesn't count the elements, it just references the existing count (so it's like accessing mySequence[0] where mySequence[0] is always an integer).

new topic     » goto parent     » topic index » view message » categorize

3. Re: Quickest way to find out if a sequence is/isn't empty?

Ah, wasn't aware of that. Thanks.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Quickest way to find out if a sequence is/isn't empty?

jimcbrown said...

length(mySequence) is the fastest. length() doesn't count the elements, it just references the existing count (so it's like accessing mySequence[0] where mySequence[0] is always an integer).

This can be extended to general objects; if you want to know whether an object is an empty sequence.
The manual states that the length of an atom is always 1, so:
length(myObject) is zero only when myObject is an empty sequence.

Arthur

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu