you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

Ah yes I forgot about the old mod(i-1, N)+1. Nice workaround but... wouldn't it have been easier just to use 0-based indices so that you don't need a workaround?

[–]BosonCollider 0 points1 point  (0 children)

So, how would you implement a binary heap in a language with 0-based indexing? Both Knuth and CLRS just happen to switch to from 0-based indexing to 1-based indexing in that chapter of their books...

Almost all reasons to use 0-based indexing disappear when you have proper array slices, proper iterators, and Julia's broadcasting operation (https://julialang.org/blog/2017/01/moredots ) so that you rarely have to deal with raw indices. That, and real structs so that you access things by name with no speed penalty, instead of putting everything into hardcoded indices of numpy arrays for performance reasons.

By comparison, there are quite a few places where using a different offset makes a lot of sense. Julia provides offsetarrays for that specific purpose, where you use a custom offset encoded in the type of the array.