6 ms·
> The argument for 1-based indexing with inclusive upper bounds is that binary heaps are easier to write this way. Nope. The argument for 1-based indexing with
by patrec 4y ago
> The argument for 1-based indexing with inclusive upper bounds is that binary heaps are easier to write this way.
Nope. The argument for 1-based indexing with inclusive upper bounds is that, to express ranges, exclusive indexes require you to have a bogus just-one-beyond-the-largest-valid-index element and a way to get the successor for every index. This is a giant PITA for anything but integers (MAX_INT, and x+1), which is why every single programming language I can think of also has end-inclusive ranges in some contexts. If you don't believe me try writing regexps with end-exclusive ranges.
On the other hand, there is no natural way to express empty ranges with 1-based indexing.
- anonymoushn 4y agoI'd love to learn more about writing regexps with various kinds of ranges. I don't see the issue, but it's very likely that I'm missing something.
- patrec 4y agoHere's what a regexp for a C-style identifier looks like (ranges are inclusive): [a-zA-Z_][a-zA-Z0-9_]* Here's what the same regexp would look like if regexp ranges were end-exclusive: [a-{A-[][a-{A-[0-:_]* Do you see the issue now? Of course if regexps really worked that way, you'd be better off doing this instead: [a-zzA-ZZ][a-zzA-ZZ0-99_] But that specific trick only works because regexp ranges occur in a set union context.
- deleted 4y ago[deleted]
- anonymoushn 4y agoI see, the `a-z` range has an inclusive upper bound. That makes sense and it really should be like that.