hashCode.String: Returns a hash code for this string

Description Usage Value Author(s) Examples

Description

Returns a hash code for this string. The hashcode for a String object is computed as

s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]

using int arithmetic, where s[i] is the ith character of the string, n is the length of the string, and ^ indicates exponentiation. (The hash value of the empty string is zero.)

Usage

1
2
## S3 method for class 'String'
hashCode(this, ...)

Value

Returns the hash code value of this String.

Author(s)

Henrik Bengtsson (http://www.braju.com/R/)

Examples

1
2
3
4
5
6
   s1 <- String("Hello world!")
   s2 <- String("Hello world!")
   hashCode(s1)              # -52967168
   hashCode(s2)              # -52967168
   hashCode("Hello world!")  # -52967168
 

HenrikBengtsson/R.lang documentation built on May 8, 2019, 7:50 p.m.