Mercurial > cpython-lru_cache-weakref
annotate Objects/mappingobject.c @ 1590:ac2e5cc29949 legacy-trunk
Added tests for missing host to open_http and open_gopher
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 18 Apr 1994 09:39:56 +0000 |
| parents | 2852edb4fffe |
| children | b724599401ff |
| rev | line source |
|---|---|
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /*********************************************************** |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 Amsterdam, The Netherlands. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 All Rights Reserved |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 provided that the above copyright notice appear in all copies and that |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 Centrum or CWI not be used in advertising or publicity pertaining to |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 distribution of the software without specific, written prior permission. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 ******************************************************************/ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 /* Mapping object implementation; using a hash table */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1256
diff
changeset
|
27 /* This file should really be called "dictobject.c", since "mapping" |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1256
diff
changeset
|
28 is the generic name for objects with an unorderred arbitrary key |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1256
diff
changeset
|
29 set (just like lists are sequences), but since it improves (and was |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1256
diff
changeset
|
30 originally derived from) a file by that name I had to change its |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1256
diff
changeset
|
31 name. For the user these objects are still called "dictionaries". */ |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1256
diff
changeset
|
32 |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 #include "allobjects.h" |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 #include "modsupport.h" |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 /* |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 Table of primes suitable as keys, in ascending order. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 The first line are the largest primes less than some powers of two, |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 the second line is the largest prime less than 6000, |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 and the third line is a selection from Knuth, Vol. 3, Sec. 6.1, Table 1. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 The final value is a sentinel and should cause the memory allocation |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 of that many entries to fail (if none of the earlier values cause such |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 failure already). |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 static unsigned int primes[] = { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 3, 7, 13, 31, 61, 127, 251, 509, 1021, 2017, 4093, |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 5987, |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 9551, 15683, 19609, 31397, |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 0xffffffff /* All bits set -- truncation OK */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 }; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 /* Object used as dummy key to fill deleted entries */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 static object *dummy; /* Initialized by first call to newmappingobject() */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 /* |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 Invariant for entries: when in use, de_value is not NULL and de_key is |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 not NULL and not dummy; when not in use, de_value is NULL and de_key |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 is either NULL or dummy. A dummy key value cannot be replaced by |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 NULL, since otherwise other keys may be lost. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 typedef struct { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 long me_hash; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 object *me_key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 object *me_value; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 } mappingentry; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 /* |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 To ensure the lookup algorithm terminates, the table size must be a |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 prime number and there must be at least one NULL key in the table. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 The value ma_fill is the number of non-NULL keys; ma_used is the number |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 of non-NULL, non-dummy keys. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 To avoid slowing down lookups on a near-full table, we resize the table |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 when it is more than half filled. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 typedef struct { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 OB_HEAD |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 int ma_fill; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 int ma_used; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 int ma_size; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 mappingentry *ma_table; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 } mappingobject; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 object * |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 newmappingobject() |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 register mappingobject *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 if (dummy == NULL) { /* Auto-initialize dummy */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 dummy = newstringobject("<dummy key>"); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 if (dummy == NULL) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 return NULL; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 mp = NEWOBJ(mappingobject, &Mappingtype); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 if (mp == NULL) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 return NULL; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 mp->ma_size = primes[0]; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 mp->ma_table = (mappingentry *) calloc(sizeof(mappingentry), mp->ma_size); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 if (mp->ma_table == NULL) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 DEL(mp); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 return err_nomem(); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 mp->ma_fill = 0; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 mp->ma_used = 0; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 return (object *)mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 /* |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 The basic lookup function used by all operations. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 This is essentially Algorithm D from Knuth Vol. 3, Sec. 6.4. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 Open addressing is preferred over chaining since the link overhead for |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 chaining would be substantial (100% with typical malloc overhead). |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 First a 32-bit hash value, 'sum', is computed from the key string. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 The first character is added an extra time shifted by 8 to avoid hashing |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 single-character keys (often heavily used variables) too close together. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 All arithmetic on sum should ignore overflow. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 The initial probe index is then computed as sum mod the table size. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 Subsequent probe indices are incr apart (mod table size), where incr |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 is also derived from sum, with the additional requirement that it is |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 relative prime to the table size (i.e., 1 <= incr < size, since the size |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 is a prime number). My choice for incr is somewhat arbitrary. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 static mappingentry *lookmapping PROTO((mappingobject *, object *, long)); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 static mappingentry * |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 lookmapping(mp, key, hash) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 register mappingobject *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
128 object *key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 long hash; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 register int i, incr; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 register unsigned long sum = (unsigned long) hash; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 register mappingentry *freeslot = NULL; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 /* We must come up with (i, incr) such that 0 <= i < ma_size |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 and 0 < incr < ma_size and both are a function of hash */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 i = sum % mp->ma_size; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 do { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 sum = sum + sum + sum + 1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 incr = sum % mp->ma_size; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 } while (incr == 0); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 for (;;) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 register mappingentry *ep = &mp->ma_table[i]; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 if (ep->me_key == NULL) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 if (freeslot != NULL) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 return freeslot; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 else |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 return ep; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 if (ep->me_key == dummy) { |
|
1406
474823e5f7dc
* parsermodule.c, Makefile, config.c: rudimentary interface to the Python
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
150 if (freeslot == NULL) |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 freeslot = ep; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 else if (ep->me_hash == hash && |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 cmpobject(ep->me_key, key) == 0) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 return ep; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 i = (i + incr) % mp->ma_size; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
159 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 /* |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 Internal routine to insert a new item into the table. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 Used both by the internal resize routine and by the public insert routine. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 Eats a reference to key and one to value. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 static void insertmapping PROTO((mappingobject *, object *, long, object *)); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 static void |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
168 insertmapping(mp, key, hash, value) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 register mappingobject *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
170 object *key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 long hash; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
172 object *value; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
173 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
174 register mappingentry *ep; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 ep = lookmapping(mp, key, hash); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 if (ep->me_value != NULL) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
177 DECREF(ep->me_value); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
178 DECREF(key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
179 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 else { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 if (ep->me_key == NULL) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 mp->ma_fill++; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 else |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 DECREF(ep->me_key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
185 ep->me_key = key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 ep->me_hash = hash; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 mp->ma_used++; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
189 ep->me_value = value; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
190 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
191 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
192 /* |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
193 Restructure the table by allocating a new table and reinserting all |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
194 items again. When entries have been deleted, the new table may |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 actually be smaller than the old one. |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 static int mappingresize PROTO((mappingobject *)); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
198 static int |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
199 mappingresize(mp) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 mappingobject *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
201 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
202 register int oldsize = mp->ma_size; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 register int newsize; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 register mappingentry *oldtable = mp->ma_table; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
205 register mappingentry *newtable; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 register mappingentry *ep; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 register int i; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 newsize = mp->ma_size; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
209 for (i = 0; ; i++) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
210 if (primes[i] > mp->ma_used*2) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
211 newsize = primes[i]; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 break; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
213 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 newtable = (mappingentry *) calloc(sizeof(mappingentry), newsize); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 if (newtable == NULL) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
217 err_nomem(); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
218 return -1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
220 mp->ma_size = newsize; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
221 mp->ma_table = newtable; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 mp->ma_fill = 0; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
223 mp->ma_used = 0; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
224 for (i = 0, ep = oldtable; i < oldsize; i++, ep++) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
225 if (ep->me_value != NULL) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
226 insertmapping(mp,ep->me_key,ep->me_hash,ep->me_value); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 else { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
228 XDECREF(ep->me_key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
229 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
231 DEL(oldtable); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
232 return 0; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
234 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
235 object * |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
236 mappinglookup(op, key) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
237 object *op; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
238 object *key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
239 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
240 long hash; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
241 if (!is_mappingobject(op)) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 err_badcall(); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
243 return NULL; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
244 } |
|
1356
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
245 #ifdef CACHE_HASH |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
246 if (!is_stringobject(key) || (hash = ((stringobject *) key)->ob_shash) == -1) |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
247 #endif |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
248 hash = hashobject(key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
249 if (hash == -1) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
250 return NULL; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
251 return lookmapping((mappingobject *)op, key, hash) -> me_value; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
252 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
253 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
254 int |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
255 mappinginsert(op, key, value) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
256 register object *op; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
257 object *key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
258 object *value; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
259 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
260 register mappingobject *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
261 register long hash; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
262 if (!is_mappingobject(op)) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
263 err_badcall(); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
264 return -1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
265 } |
|
1356
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
266 #ifdef CACHE_HASH |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
267 if (!is_stringobject(key) || (hash = ((stringobject *) key)->ob_shash) == -1) |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
268 #endif |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
269 hash = hashobject(key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
270 if (hash == -1) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
271 return -1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 mp = (mappingobject *)op; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
273 /* if fill >= 2/3 size, resize */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
274 if (mp->ma_fill*3 >= mp->ma_size*2) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
275 if (mappingresize(mp) != 0) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 if (mp->ma_fill+1 > mp->ma_size) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
277 return -1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
278 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
279 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 INCREF(value); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
281 INCREF(key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
282 insertmapping(mp, key, hash, value); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
283 return 0; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
285 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
286 int |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 mappingremove(op, key) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 object *op; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
289 object *key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
290 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
291 register mappingobject *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
292 register long hash; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
293 register mappingentry *ep; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
294 if (!is_mappingobject(op)) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
295 err_badcall(); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
296 return -1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
297 } |
|
1356
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
298 #ifdef CACHE_HASH |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
299 if (!is_stringobject(key) || (hash = ((stringobject *) key)->ob_shash) == -1) |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
300 #endif |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
301 hash = hashobject(key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
302 if (hash == -1) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 return -1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
304 mp = (mappingobject *)op; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
305 ep = lookmapping(mp, key, hash); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 if (ep->me_value == NULL) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 err_setval(KeyError, key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
308 return -1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
309 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 DECREF(ep->me_key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
311 INCREF(dummy); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 ep->me_key = dummy; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
313 DECREF(ep->me_value); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
314 ep->me_value = NULL; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
315 mp->ma_used--; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
316 return 0; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
317 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
318 |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
319 void |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
320 mappingclear(op) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
321 object *op; |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
323 int i; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
324 register mappingobject *mp; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
325 if (!is_mappingobject(op)) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
326 return; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
327 mp = (mappingobject *)op; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
328 for (i = 0; i < mp->ma_size; i++) { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
329 XDECREF(mp->ma_table[i].me_key); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
330 XDECREF(mp->ma_table[i].me_value); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
331 mp->ma_table[i].me_key = NULL; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
332 mp->ma_table[i].me_value = NULL; |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
333 } |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
334 mp->ma_used = 0; |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
337 int |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
338 mappinggetnext(op, ppos, pkey, pvalue) |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 object *op; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
340 int *ppos; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
341 object **pkey; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
342 object **pvalue; |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
343 { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
344 int i; |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
345 register mappingobject *mp; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
346 if (!is_dictobject(op)) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
347 return 0; |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
348 mp = (mappingobject *)op; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
349 i = *ppos; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
350 if (i < 0) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
351 return 0; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
352 while (i < mp->ma_size && mp->ma_table[i].me_value == NULL) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
353 i++; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
354 *ppos = i+1; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
355 if (i >= mp->ma_size) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
356 return 0; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
357 if (pkey) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
358 *pkey = mp->ma_table[i].me_key; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
359 if (pvalue) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
360 *pvalue = mp->ma_table[i].me_value; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
361 return 1; |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
362 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
363 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 /* Methods */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
365 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
366 static void |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 mapping_dealloc(mp) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
368 register mappingobject *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
369 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 register int i; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
371 register mappingentry *ep; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
372 for (i = 0, ep = mp->ma_table; i < mp->ma_size; i++, ep++) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
373 if (ep->me_key != NULL) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
374 DECREF(ep->me_key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
375 if (ep->me_value != NULL) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
376 DECREF(ep->me_value); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
377 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
378 if (mp->ma_table != NULL) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
379 DEL(mp->ma_table); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 DEL(mp); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
381 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
382 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
383 static int |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
384 mapping_print(mp, fp, flags) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 register mappingobject *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 register FILE *fp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
387 register int flags; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
388 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
389 register int i; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
390 register int any; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
391 register mappingentry *ep; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
392 fprintf(fp, "{"); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
393 any = 0; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
394 for (i = 0, ep = mp->ma_table; i < mp->ma_size; i++, ep++) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 if (ep->me_value != NULL) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
396 if (any++ > 0) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
397 fprintf(fp, ", "); |
|
1405
90c5e2bb4da5
* posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents:
1398
diff
changeset
|
398 if (printobject((object *)ep->me_key, fp, 0) != 0) |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
399 return -1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
400 fprintf(fp, ": "); |
|
1405
90c5e2bb4da5
* posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents:
1398
diff
changeset
|
401 if (printobject(ep->me_value, fp, 0) != 0) |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
402 return -1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
403 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
404 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
405 fprintf(fp, "}"); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
406 return 0; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
407 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
408 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
409 static void |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
410 js(pv, w) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
411 object **pv; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
412 object *w; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
413 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
414 joinstring(pv, w); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
415 XDECREF(w); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
416 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
417 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
418 static object * |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
419 mapping_repr(mp) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
420 mappingobject *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
421 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
422 auto object *v; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
423 object *sepa, *colon; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
424 register int i; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
425 register int any; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
426 register mappingentry *ep; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
427 v = newstringobject("{"); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
428 sepa = newstringobject(", "); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
429 colon = newstringobject(": "); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
430 any = 0; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
431 for (i = 0, ep = mp->ma_table; i < mp->ma_size; i++, ep++) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
432 if (ep->me_value != NULL) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
433 if (any++) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
434 joinstring(&v, sepa); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
435 js(&v, reprobject(ep->me_key)); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
436 joinstring(&v, colon); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
437 js(&v, reprobject(ep->me_value)); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
438 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
439 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
440 js(&v, newstringobject("}")); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
441 XDECREF(sepa); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
442 XDECREF(colon); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
443 return v; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
444 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
445 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
446 static int |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
447 mapping_length(mp) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
448 mappingobject *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
449 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
450 return mp->ma_used; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
451 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
452 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
453 static object * |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
454 mapping_subscript(mp, key) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
455 mappingobject *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
456 register object *key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
457 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
458 object *v; |
|
1356
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
459 long hash; |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
460 #ifdef CACHE_HASH |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
461 if (!is_stringobject(key) || (hash = ((stringobject *) key)->ob_shash) == -1) |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
462 #endif |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
463 hash = hashobject(key); |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
464 if (hash == -1) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
465 return NULL; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
466 v = lookmapping(mp, key, hash) -> me_value; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
467 if (v == NULL) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
468 err_setval(KeyError, key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
469 else |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
470 INCREF(v); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
471 return v; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
472 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
473 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
474 static int |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
475 mapping_ass_sub(mp, v, w) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
476 mappingobject *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
477 object *v, *w; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
478 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
479 if (w == NULL) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
480 return mappingremove((object *)mp, v); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
481 else |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
482 return mappinginsert((object *)mp, v, w); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
483 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
484 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
485 static mapping_methods mapping_as_mapping = { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
486 mapping_length, /*mp_length*/ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
487 mapping_subscript, /*mp_subscript*/ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
488 mapping_ass_sub, /*mp_ass_subscript*/ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
489 }; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
490 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
491 static object * |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
492 mapping_keys(mp, args) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
493 register mappingobject *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
494 object *args; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
495 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
496 register object *v; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
497 register int i, j; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
498 if (!getnoarg(args)) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
499 return NULL; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
500 v = newlistobject(mp->ma_used); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
501 if (v == NULL) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
502 return NULL; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
503 for (i = 0, j = 0; i < mp->ma_size; i++) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
504 if (mp->ma_table[i].me_value != NULL) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
505 object *key = mp->ma_table[i].me_key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
506 INCREF(key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
507 setlistitem(v, j, key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
508 j++; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
509 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
510 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
511 return v; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
512 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
513 |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
514 static object * |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
515 mapping_values(mp, args) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
516 register mappingobject *mp; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
517 object *args; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
518 { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
519 register object *v; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
520 register int i, j; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
521 if (!getnoarg(args)) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
522 return NULL; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
523 v = newlistobject(mp->ma_used); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
524 if (v == NULL) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
525 return NULL; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
526 for (i = 0, j = 0; i < mp->ma_size; i++) { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
527 if (mp->ma_table[i].me_value != NULL) { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
528 object *value = mp->ma_table[i].me_value; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
529 INCREF(value); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
530 setlistitem(v, j, value); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
531 j++; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
532 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
533 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
534 return v; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
535 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
536 |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
537 static object * |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
538 mapping_items(mp, args) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
539 register mappingobject *mp; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
540 object *args; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
541 { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
542 register object *v; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
543 register int i, j; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
544 if (!getnoarg(args)) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
545 return NULL; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
546 v = newlistobject(mp->ma_used); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
547 if (v == NULL) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
548 return NULL; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
549 for (i = 0, j = 0; i < mp->ma_size; i++) { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
550 if (mp->ma_table[i].me_value != NULL) { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
551 object *key = mp->ma_table[i].me_key; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
552 object *value = mp->ma_table[i].me_value; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
553 object *item = newtupleobject(2); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
554 if (item == NULL) { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
555 DECREF(v); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
556 return NULL; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
557 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
558 INCREF(key); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
559 settupleitem(item, 0, key); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
560 INCREF(value); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
561 settupleitem(item, 1, value); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
562 setlistitem(v, j, item); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
563 j++; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
564 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
565 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
566 return v; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
567 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
568 |
|
1398
1d841587aede
Added getmappingsize(). (Needed by previous checkin of posixmodule.c)
Guido van Rossum <guido@python.org>
parents:
1356
diff
changeset
|
569 int |
|
1d841587aede
Added getmappingsize(). (Needed by previous checkin of posixmodule.c)
Guido van Rossum <guido@python.org>
parents:
1356
diff
changeset
|
570 getmappingsize(mp) |
|
1d841587aede
Added getmappingsize(). (Needed by previous checkin of posixmodule.c)
Guido van Rossum <guido@python.org>
parents:
1356
diff
changeset
|
571 object *mp; |
|
1d841587aede
Added getmappingsize(). (Needed by previous checkin of posixmodule.c)
Guido van Rossum <guido@python.org>
parents:
1356
diff
changeset
|
572 { |
|
1d841587aede
Added getmappingsize(). (Needed by previous checkin of posixmodule.c)
Guido van Rossum <guido@python.org>
parents:
1356
diff
changeset
|
573 if (mp == NULL || !is_mappingobject(mp)) { |
|
1d841587aede
Added getmappingsize(). (Needed by previous checkin of posixmodule.c)
Guido van Rossum <guido@python.org>
parents:
1356
diff
changeset
|
574 err_badcall(); |
|
1413
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1406
diff
changeset
|
575 return 0; |
|
1398
1d841587aede
Added getmappingsize(). (Needed by previous checkin of posixmodule.c)
Guido van Rossum <guido@python.org>
parents:
1356
diff
changeset
|
576 } |
|
1d841587aede
Added getmappingsize(). (Needed by previous checkin of posixmodule.c)
Guido van Rossum <guido@python.org>
parents:
1356
diff
changeset
|
577 return ((mappingobject *)mp)->ma_used; |
|
1d841587aede
Added getmappingsize(). (Needed by previous checkin of posixmodule.c)
Guido van Rossum <guido@python.org>
parents:
1356
diff
changeset
|
578 } |
|
1d841587aede
Added getmappingsize(). (Needed by previous checkin of posixmodule.c)
Guido van Rossum <guido@python.org>
parents:
1356
diff
changeset
|
579 |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
580 object * |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
581 getmappingkeys(mp) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
582 object *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
583 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
584 if (mp == NULL || !is_mappingobject(mp)) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
585 err_badcall(); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
586 return NULL; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
587 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
588 return mapping_keys((mappingobject *)mp, (object *)NULL); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
589 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
590 |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
591 object * |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
592 getmappingvalues(mp) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
593 object *mp; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
594 { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
595 if (mp == NULL || !is_mappingobject(mp)) { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
596 err_badcall(); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
597 return NULL; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
598 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
599 return mapping_values((mappingobject *)mp, (object *)NULL); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
600 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
601 |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
602 object * |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
603 getmappingitems(mp) |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
604 object *mp; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
605 { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
606 if (mp == NULL || !is_mappingobject(mp)) { |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
607 err_badcall(); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
608 return NULL; |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
609 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
610 return mapping_values((mappingobject *)mp, (object *)NULL); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
611 } |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
612 |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
613 static int |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
614 mapping_compare(a, b) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
615 mappingobject *a, *b; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
616 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
617 object *akeys, *bkeys; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
618 int i, n, res; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
619 if (a == b) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
620 return 0; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
621 if (a->ma_used == 0) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
622 if (b->ma_used != 0) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
623 return -1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
624 else |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
625 return 0; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
626 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
627 else { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
628 if (b->ma_used == 0) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
629 return 1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
630 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
631 akeys = mapping_keys(a, (object *)NULL); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
632 bkeys = mapping_keys(b, (object *)NULL); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
633 if (akeys == NULL || bkeys == NULL) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
634 /* Oops, out of memory -- what to do? */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
635 /* For now, sort on address! */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
636 XDECREF(akeys); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
637 XDECREF(bkeys); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
638 if (a < b) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
639 return -1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
640 else |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
641 return 1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
642 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
643 sortlist(akeys); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
644 sortlist(bkeys); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
645 n = a->ma_used < b->ma_used ? a->ma_used : b->ma_used; /* smallest */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
646 res = 0; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
647 for (i = 0; i < n; i++) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
648 object *akey, *bkey, *aval, *bval; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
649 long ahash, bhash; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
650 akey = getlistitem(akeys, i); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
651 bkey = getlistitem(bkeys, i); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
652 res = cmpobject(akey, bkey); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
653 if (res != 0) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
654 break; |
|
1356
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
655 #ifdef CACHE_HASH |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
656 if (!is_stringobject(akey) || (ahash = ((stringobject *) akey)->ob_shash) == -1) |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
657 #endif |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
658 ahash = hashobject(akey); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
659 if (ahash == -1) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
660 err_clear(); /* Don't want errors here */ |
|
1356
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
661 #ifdef CACHE_HASH |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
662 if (!is_stringobject(bkey) || (bhash = ((stringobject *) bkey)->ob_shash) == -1) |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
663 #endif |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
664 bhash = hashobject(bkey); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
665 if (bhash == -1) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
666 err_clear(); /* Don't want errors here */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
667 aval = lookmapping(a, akey, ahash) -> me_value; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
668 bval = lookmapping(b, bkey, bhash) -> me_value; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
669 res = cmpobject(aval, bval); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
670 if (res != 0) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
671 break; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
672 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
673 if (res == 0) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
674 if (a->ma_used < b->ma_used) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
675 res = -1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
676 else if (a->ma_used > b->ma_used) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
677 res = 1; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
678 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
679 DECREF(akeys); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
680 DECREF(bkeys); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
681 return res; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
682 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
683 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
684 static object * |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
685 mapping_has_key(mp, args) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
686 register mappingobject *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
687 object *args; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
688 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
689 object *key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
690 long hash; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
691 register long ok; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
692 if (!getargs(args, "O", &key)) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
693 return NULL; |
|
1356
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
694 #ifdef CACHE_HASH |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
695 if (!is_stringobject(key) || (hash = ((stringobject *) key)->ob_shash) == -1) |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
696 #endif |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
697 hash = hashobject(key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
698 if (hash == -1) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
699 return NULL; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
700 ok = lookmapping(mp, key, hash)->me_value != NULL; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
701 return newintobject(ok); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
702 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
703 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
704 static struct methodlist mapp_methods[] = { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
705 {"has_key", mapping_has_key}, |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
706 {"items", mapping_items}, |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
707 {"keys", mapping_keys}, |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
708 {"values", mapping_values}, |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
709 {NULL, NULL} /* sentinel */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
710 }; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
711 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
712 static object * |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
713 mapping_getattr(mp, name) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
714 mappingobject *mp; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
715 char *name; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
716 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
717 return findmethod(mapp_methods, (object *)mp, name); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
718 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
719 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
720 typeobject Mappingtype = { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
721 OB_HEAD_INIT(&Typetype) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
722 0, |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1256
diff
changeset
|
723 "dictionary", |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
724 sizeof(mappingobject), |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
725 0, |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
726 mapping_dealloc, /*tp_dealloc*/ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
727 mapping_print, /*tp_print*/ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
728 mapping_getattr, /*tp_getattr*/ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
729 0, /*tp_setattr*/ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
730 mapping_compare, /*tp_compare*/ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
731 mapping_repr, /*tp_repr*/ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
732 0, /*tp_as_number*/ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
733 0, /*tp_as_sequence*/ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
734 &mapping_as_mapping, /*tp_as_mapping*/ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
735 }; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
736 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
737 /* For backward compatibility with old dictionary interface */ |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
738 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
739 static object *last_name_object; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
740 static char *last_name_char; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
741 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
742 object * |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
743 getattro(v, name) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
744 object *v; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
745 object *name; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
746 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
747 if (name != last_name_object) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
748 XDECREF(last_name_object); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
749 INCREF(name); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
750 last_name_object = name; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
751 last_name_char = getstringvalue(name); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
752 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
753 return getattr(v, last_name_char); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
754 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
755 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
756 int |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
757 setattro(v, name, value) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
758 object *v; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
759 object *name; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
760 object *value; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
761 { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
762 if (name != last_name_object) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
763 XDECREF(last_name_object); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
764 INCREF(name); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
765 last_name_object = name; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
766 last_name_char = getstringvalue(name); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
767 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
768 return setattr(v, last_name_char, value); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
769 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
770 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
771 object * |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
772 dictlookup(v, key) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
773 object *v; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
774 char *key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
775 { |
|
1414
2852edb4fffe
Fix lay-out of previous fix.
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
776 if (key != last_name_char || |
|
2852edb4fffe
Fix lay-out of previous fix.
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
777 strcmp(key, getstringvalue(last_name_object)) != 0) { |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
778 XDECREF(last_name_object); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
779 last_name_object = newstringobject(key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
780 if (last_name_object == NULL) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
781 last_name_char = NULL; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
782 return NULL; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
783 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
784 last_name_char = key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
785 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
786 return mappinglookup(v, last_name_object); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
787 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
788 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
789 int |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
790 dictinsert(v, key, item) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
791 object *v; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
792 char *key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
793 object *item; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
794 { |
|
1414
2852edb4fffe
Fix lay-out of previous fix.
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
795 if (key != last_name_char || |
|
2852edb4fffe
Fix lay-out of previous fix.
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
796 strcmp(key, getstringvalue(last_name_object)) != 0) { |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
797 XDECREF(last_name_object); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
798 last_name_object = newstringobject(key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
799 if (last_name_object == NULL) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
800 last_name_char = NULL; |
|
1330
409ea74feb21
Minor fixes / changes for Mac compatibility.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
801 return -1; |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
802 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
803 last_name_char = key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
804 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
805 return mappinginsert(v, last_name_object, item); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
806 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
807 |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
808 int |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
809 dictremove(v, key) |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
810 object *v; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
811 char *key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
812 { |
|
1413
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1406
diff
changeset
|
813 if (key != last_name_char || |
|
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1406
diff
changeset
|
814 strcmp(key, getstringvalue(last_name_object)) != 0) { |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
815 XDECREF(last_name_object); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
816 last_name_object = newstringobject(key); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
817 if (last_name_object == NULL) { |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
818 last_name_char = NULL; |
|
1330
409ea74feb21
Minor fixes / changes for Mac compatibility.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
819 return -1; |
|
1256
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
820 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
821 last_name_char = key; |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
822 } |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
823 return mappingremove(v, last_name_object); |
|
7aa9613ffd36
Generalized version of dictionaries, with compatibility hacks.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
824 } |
