Home > Blockchain >  WHATWG: Infra Standard - Clarification (Should be consecutive? Get the indices incorrect definition?
WHATWG: Infra Standard - Clarification (Should be consecutive? Get the indices incorrect definition?

Time:10-06

I'm creating a List data structure in PHP based off of the WHATWG Infra Standard as a programming exercise and am having some issues trying to clarify a couple items.

  1. I don't see anywhere that implies that indices in a list must be consecutive. However, it seems to be implied in the definition of getting the indices of a list:

To get the indices of a list, return the range from 0 to the list’s size, exclusive.

  1. In the definition of getting the indices (listed above) it says to return the range from 0 to the list's size, but wouldn't this include one extra index than is actually present? I see the sentence ends with ", exclusive" but I don't know what that means in this context.

Any insight is much appreciated!

CodePudding user response:

There is no operation that would allow for a "sparse" list if that's what you are asking for.
Removing items from a list will make the following items "move" to fill the now empty positions.

And regarding "return the range from 0 to the list’s size, exclusive." "range" is a link to https://infra.spec.whatwg.org/#the-exclusive-range, which states

The range n to m, exclusive, creates a new ordered set containing all of the integers from n up to and including m − 1 in consecutively increasing order, as long as m is greater than n. If m equals n, then it creates an empty ordered set.

Don't be afraid of following all the links in the specs if you want to implement it.

  • Related