From: Gurusamy Sarathy Date: Sat, 28 Nov 1998 09:36:40 +0000 (+0000) Subject: document changed PERL_HASH() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ab19240082dfba31ce2fd03e2c5d9e7779bcdc76;p=p5sagit%2Fp5-mst-13.2.git document changed PERL_HASH() p4raw-id: //depot/perl@2333 --- diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 2d1e1df..8852b18 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -1047,9 +1047,13 @@ element in the hash. (Note: Keys may be C<"0"> or C<"">, which are logically false; you may wish to avoid constructs like C for this reason.) -Entries are returned in an apparently random order. When the hash is -entirely read, a null array is returned in list context (which when -assigned produces a FALSE (C<0>) value), and C in +Entries are returned in an apparently random order. The actual random +order is subject to change in future versions of perl, but it is guaranteed +to be in the same order as either the C or C function +would produce on the same (unmodified) hash. + +When the hash is entirely read, a null array is returned in list context +(which when assigned produces a FALSE (C<0>) value), and C in scalar context. The next call to C after that will start iterating again. There is a single iterator for each hash, shared by all C, C, and C function calls in the program; it can be reset by @@ -1064,7 +1068,7 @@ only in a different order: print "$key=$value\n"; } -See also C and C. +See also C, C and C. =item else BLOCK @@ -1985,9 +1989,11 @@ See L. Returns a list consisting of all the keys of the named hash. (In a scalar context, returns the number of keys.) The keys are returned in -an apparently random order, but it is the same order as either the -C or C function produces (given that the hash has not been -modified). As a side effect, it resets HASH's iterator. +an apparently random order. The actual random order is subject to +change in future versions of perl, but it is guaranteed to be the same +order as either the C or C function produces (given +that the hash has not been modified). As a side effect, it resets +HASH's iterator. Here is yet another way to print your environment: @@ -2017,14 +2023,16 @@ an array by assigning a larger number to $#array.) If you say keys %hash = 200; -then C<%hash> will have at least 200 buckets allocated for it--256 of them, in fact, since -it rounds up to the next power of two. These +then C<%hash> will have at least 200 buckets allocated for it--256 of them, +in fact, since it rounds up to the next power of two. These buckets will be retained even if you do C<%hash = ()>, use C if you want to free the storage while C<%hash> is still in scope. You can't shrink the number of buckets allocated for the hash using C in this way (but you needn't worry about doing this by accident, as trying has no effect). +See also C, C and C. + =item kill LIST Sends a signal to a list of processes. The first element of @@ -4475,8 +4483,11 @@ command if the files already exist: Returns a list consisting of all the values of the named hash. (In a scalar context, returns the number of values.) The values are -returned in an apparently random order, but it is the same order as -either the C or C function would produce on the same hash. +returned in an apparently random order. The actual random order is +subject to change in future versions of perl, but it is guaranteed to +be the same order as either the C or C function would +produce on the same (unmodified) hash. + As a side effect, it resets HASH's iterator. See also C, C, and C. diff --git a/pod/perlguts.pod b/pod/perlguts.pod index 7ccb80e..b835b59 100644 --- a/pod/perlguts.pod +++ b/pod/perlguts.pod @@ -350,11 +350,13 @@ This returns NULL if the variable does not exist. The hash algorithm is defined in the C macro: - i = klen; hash = 0; - s = key; - while (i--) - hash = hash * 33 + *s++; + while (klen--) + hash = (hash * 33) + *key++; + hash = hash + (hash >> 5); /* after 5.006 */ + +The last step was added in version 5.006 to improve distribution of +lower bits in the resulting hash value. See L for more information on how to use the hash access functions on tied hashes.