summaryrefslogtreecommitdiffstats
path: root/Objects/stringobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-03-29 10:43:31 (GMT)
committerGuido van Rossum <guido@python.org>1993-03-29 10:43:31 (GMT)
commit9bfef44d97d1ae24e03717e3d59024b44626a9de (patch)
tree736b9f406d27f9dc4496f103cd395fb7a97401d4 /Objects/stringobject.c
parent4b1302bd1d211881178618aa8f41fa4460180f2e (diff)
downloadcpython-9bfef44d97d1ae24e03717e3d59024b44626a9de.zip
cpython-9bfef44d97d1ae24e03717e3d59024b44626a9de.tar.gz
cpython-9bfef44d97d1ae24e03717e3d59024b44626a9de.tar.bz2
* 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
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r--Objects/stringobject.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 25f12fc..5c7345d 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -293,6 +293,21 @@ string_compare(a, b)
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 @@ typeobject Stringtype = {
0, /*tp_as_number*/
&string_as_sequence, /*tp_as_sequence*/
0, /*tp_as_mapping*/
+ string_hash, /*tp_hash*/
};
void