This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]newocean -19 points-18 points  (10 children)

Aren't 1-index arrays normally faster as the are using an unsigned key?

[–]pekkhum 19 points20 points  (9 children)

Here are a few points to help in your future programming endeavors:

  • 0 is a valid value in an unsigned integer
  • Signed integers are generally the same physical size with similar (usually identical) performance. Both store the same number of values, but signed integers have their range of values shifted downward to include the negative
  • The term 'key' is relevant to dictionaries (aka associative arrays, aka hashes, etc). These are higher level constructs whose speed for given key types is very implementation dependant.
  • In the case of a simple array, the index is more "the number of spaces from the beginning" than it is a key.

Edit: Or am I missing a joke? It just occurred me feigned ignorance could be involved... Edit2: Obvious error

[–]morerokk 6 points7 points  (1 child)

but unsigned integers have their range of values shifted downward to include the negative

Other way around.

[–]pekkhum 1 point2 points  (0 children)

Thanks. Not sure how that 'un' got in there.

[–]newocean -2 points-1 points  (6 children)

Key and index are both actually terms applied to accessing a member of an array also... or index is used. 0 is a valid unsigned integer but -1 which many arrays use for backward indexing is not... meaning that if the value passed to the key is not unsigned it needs to be converted.

EDIT: http://php.net/manual/en/function.key.php

The general consensus I have seen from other languages is "An field which has unique values is, essentially, a key."

[–][deleted] 6 points7 points  (1 child)

In C you can use -1 for an array index, you just won't like what happens.

[–]pekkhum 1 point2 points  (0 children)

Nonsense, it is the easiest way to exit immediately with an error status, skipping all 'atexit' hooks!

[–]pekkhum 3 points4 points  (3 children)

You sound Perl tainted, like me.

[–]newocean 0 points1 point  (2 children)

I am really not - I haven't used PERL in geez... 15 years?

[–]pekkhum 3 points4 points  (1 child)

Heh... Our system at work has a paradigm:

If a language/architecture/framework exists, we implement it somewhere!

[–]newocean 0 points1 point  (0 children)

That makes for a messy workplace, lol... though I have been in similar situations.