Mercurial > cpython-lru_cache-weakref
diff Objects/stringobject.c @ 1257:1cabc2b6c970 legacy-trunk
* Changed all copyright messages to include 1993.
* Stubs for faster implementation of local variables (not yet finished)
* Added function name to code object. Print it for code and function
objects. THIS MAKES THE .PYC FILE FORMAT INCOMPATIBLE (the version
number has changed accordingly)
* Print address of self for built-in methods
* New internal functions getattro and setattro (getattr/setattr with
string object arg)
* Replaced "dictobject" with more powerful "mappingobject"
* New per-type functio tp_hash to implement arbitrary object hashing,
and hashobject() to interface to it
* Added built-in functions hash(v) and hasattr(v, 'name')
* classobject: made some functions static that accidentally weren't;
added __hash__ special instance method to implement hash()
* Added proper comparison for built-in methods and functions
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 29 Mar 1993 10:43:31 +0000 |
| parents | c4cd0d9d8281 |
| children | e0464e7115ca |
line wrap: on
line diff
--- a/Objects/stringobject.c Sat Mar 27 18:11:32 1993 +0000 +++ b/Objects/stringobject.c Mon Mar 29 10:43:31 1993 +0000 @@ -293,6 +293,21 @@ return (len_a < len_b) ? -1 : (len_a > len_b) ? 1 : 0; } +static long +string_hash(a) + stringobject *a; +{ + register int len = a->ob_size; + register unsigned char *p = (unsigned char *) a->ob_sval; + register long x = *p << 7; + while (--len >= 0) + x = (x + x + x) ^ *p++; + x ^= a->ob_size; + if (x == -1) + x = -2; + return x; +} + static sequence_methods string_as_sequence = { string_length, /*sq_length*/ string_concat, /*sq_concat*/ @@ -318,6 +333,7 @@ 0, /*tp_as_number*/ &string_as_sequence, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ + string_hash, /*tp_hash*/ }; void
