Commit Graph

62 Commits

Author SHA1 Message Date
Martin v. Löwis 18e165558b Merge ssize_t branch. 2006-02-15 17:27:45 +00:00
Armin Rigo f5b3e36493 Renamed _length_cue() to __length_hint__(). See:
http://mail.python.org/pipermail/python-dev/2006-February/060524.html
2006-02-11 21:32:43 +00:00
Neal Norwitz 0c6e2f1640 Remove some shadowed variables 2006-01-08 06:13:44 +00:00
Neal Norwitz 6576bd844f Prevent name pollution by making lots of internal functions static. 2005-11-13 18:41:28 +00:00
Raymond Hettinger 6b27cda643 Convert iterator __len__() methods to a private API. 2005-09-24 21:23:05 +00:00
Raymond Hettinger 9bda1d6f64 No longer ignore exceptions raised by comparisons during key lookup.
Inspired by Armin Rigo's suggestion to do the same with dictionaries.
2005-09-16 07:14:21 +00:00
Georg Brandl 02c42871cf Disallow keyword arguments for type constructors that don't use them.
(fixes bug #1119418)
2005-08-26 06:42:30 +00:00
Raymond Hettinger 9c1491f37c * Add a fast equality check path for frozensets where the hash value has
already been computed.
* Apply a GET_SIZE macro().
2005-08-24 00:24:40 +00:00
Raymond Hettinger d8e133865d Add shortcuts for a|a and a&a. 2005-08-17 12:27:17 +00:00
Raymond Hettinger f408ddf4a0 Results of a line-by-line comparison back to dictobject.c.
* set_merge() cannot assume that the table doesn't resize during iteration.

* convert some unnecessary tests to asserts -- they were necessary in
  dictobject.c because PyDict_Next() is a public function.  The same is
  not true for set_next().

* re-arrange the order of functions to more closely match the order
  in dictobject.c.  This makes it must easier to compare the two
  and ought to simplify any issues of maintaining both.
2005-08-17 00:27:42 +00:00
Raymond Hettinger c47e01d020 Numerous fix-ups to C API and docs. Added tests for C API. 2005-08-16 10:44:15 +00:00
Raymond Hettinger 994c2c1c69 DECREF --> XDECREF 2005-08-16 03:54:11 +00:00
Raymond Hettinger beb3101b05 Add a C API for sets and frozensets. 2005-08-16 03:47:52 +00:00
Raymond Hettinger ce8185e642 More function re-ordering (placing like functions together). 2005-08-13 09:28:48 +00:00
Raymond Hettinger ed6c1ef8c3 * Bring lookkey() and lookkey_string() closer to dict version.
* Use set_next() for looping in issubset() and frozenset_hash().
* Re-order the presentation of cmp and hash functions.
2005-08-13 08:28:03 +00:00
Raymond Hettinger b02c35e208 * Fix SF #1257731. Make __contains__(), remove(), and discard() only do
a frozenset conversion when the initial search attempt fails with a
  TypeError and the key is some type of set.  Add a testcase.

* Eliminate a duplicate if-stmt.
2005-08-12 20:48:39 +00:00
Raymond Hettinger c991db240c * Add short-circuit code for in-place operations with self (such as
s|=s, s&=s, s-=s, or s^=s).  Add related tests.

* Improve names for several variables and functions.

* Provide alternate table access functions (next, contains, add, and discard)
  that work with an entry argument instead of just a key.  This improves
  set-vs-set operations because we already have a hash value for each key
  and can avoid unnecessary calls to PyObject_Hash().  Provides a 5% to 20%
  speed-up for quick hashing elements like strings and integers.  Provides
  much more substantial improvements for slow hashing elements like tuples
  or objects defining a custom __hash__() function.

* Have difference operations resize() when 1/5 of the elements are dummies.
  Formerly, it was 1/6.  The new ratio triggers less frequently and only
  in cases that it can resize quicker and with greater benefit.  The right
  answer is probably either 1/4, 1/5, or 1/6.  Picked the middle value for
  an even trade-off between resize time and the space/time costs of dummy
  entries.
2005-08-11 07:58:45 +00:00
Raymond Hettinger bc841a1464 * Bring in INIT_NONZERO_SET_SLOTS macro from dictionary code.
* Bring in free list from dictionary code.
* Improve several comments.
* Differencing can leave many dummy entries.  If more than
  1/6 are dummies, then resize them away.
* Factor-out common code with new macro, PyAnySet_CheckExact.
2005-08-07 13:02:53 +00:00
Raymond Hettinger 99220fabb1 * Removed checked_error flag which no longer provides any benefit.
* Have issubset() control its own loop instead of using set_next_internal().
2005-08-06 18:57:13 +00:00
Raymond Hettinger 5ba0cbe392 * set_new() doesn't need to zero the structure a second time after tp_alloc
has already done the job.
* Use a macro form of PyErr_Occurred() inside the set_lookkey() function.
2005-08-06 18:31:24 +00:00
Raymond Hettinger fe889f3c62 Factor away a redundant clear() function. 2005-08-06 05:43:39 +00:00
Raymond Hettinger a580c47c6d * Improve a variable name: entry0 --> table.
* Give set_lookkey_string() a fast alternate path when no dummy entries
  are present.
* Have set_swap_bodies() reset the hash field to -1 whenever either of
  bodies is not a frozenset.  Maintains the invariant of regular sets
  always having -1 in the hash field; otherwise, any mutation would make
  the hash value invalid.
* Use an entry pointer to simplify the code in frozenset_hash().
2005-08-05 17:19:54 +00:00
Raymond Hettinger a9d9936d10 * Move copyright notice to top and indicate derivation from sets.py and
dictobject.c.
* Have frozenset_hash() use entry->hash instead of re-computing each
  individual hash with PyObject_Hash(o);
* Finalize the dummy entry before a system exit.
2005-08-05 00:01:15 +00:00
Raymond Hettinger 67962ab1bb Model set.pop() after dict.popitem(). 2005-08-02 03:45:16 +00:00
Raymond Hettinger d794666048 * Improve code for the empty frozenset singleton:
- Handle both frozenset() and frozenset([]).
  - Do not use singleton for frozenset subclasses.
  - Finalize the singleton.
  - Add test cases.
* Factor-out set_update_internal() from set_update().  Simplifies the
  code for several internal callers.
* Factor constant expressions out of loop in set_merge_internal().
* Minor comment touch-ups.
2005-08-01 21:39:29 +00:00
Hye-Shik Chang e295676c87 Fix build on gcc: PySetIter_Type should be static in definition
part also.
2005-08-01 05:26:41 +00:00
Raymond Hettinger 06d8cf8ceb Improve variable names. 2005-07-31 15:36:06 +00:00
Raymond Hettinger 9dcb17cb1a Fix frozenset() ref count and a comment typo. 2005-07-31 13:09:28 +00:00
Raymond Hettinger 934d63eb40 Comment on the set_swap_bodies() helper function. 2005-07-31 01:33:10 +00:00
Raymond Hettinger 9f1a6796eb Revised the set() and frozenset() implementaion to use its own internal
data structure instead of using dictionaries.  Reduces memory consumption
by 1/3 and provides modest speed-ups for most set operations.
2005-07-31 01:16:36 +00:00
Raymond Hettinger bb999b5925 SF patch #1200018: Restore GC support to set objects
Reverts 1.26 and 1.27.
And adds cycle testing.
2005-06-18 21:00:26 +00:00
Raymond Hettinger 15056a5202 SF 1062353: set pickling problems
Support automatic pickling of dictionaries in instance of set subclasses.
2004-11-09 07:25:31 +00:00
Raymond Hettinger 6429a4727e Use Py_CLEAR(). Add unrelated test. 2004-09-28 01:51:35 +00:00
Nicholas Bastin 9ba301e589 Moved SunPro warning suppression into pyport.h and out of individual
modules and objects.
2004-07-15 15:54:05 +00:00
Nicholas Bastin 1ce9e4cfc1 Fixed end-of-loop code not reached warning when using SunPro C 2004-06-17 18:27:18 +00:00
Raymond Hettinger 148a63f1fc Remove a function no longer in use. 2004-06-14 04:24:41 +00:00
Raymond Hettinger 47edb4b09c Remove unnecessary GC support. Sets cannot have cycles. 2004-06-13 08:20:46 +00:00
Raymond Hettinger c978633ec6 Futher improvements to frozenset hashing (based on Yitz Gale's battery of
tests which nicely highly highlight weaknesses).

* Initial value is now a large prime.
* Pre-multiply by the set length to add one more basis of differentiation.
* Work a bit harder inside the loop to scatter bits from sources that
  may have closely spaced hash values.

All of this is necessary to make up for keep the hash function commutative.
Fortunately, the hash value is cached so the call to frozenset_hash() will
only occur once per set.
2004-06-10 22:41:48 +00:00
Raymond Hettinger 27e403ebe9 Fixups to the hash function for frozensets.
* Non-zero initial value so that hash(frozenset()) != hash(0).
* Final permutation to differentiate nested sets.
* Add logic to make sure that -1 is not a possible hash value.
2004-06-10 21:38:41 +00:00
Raymond Hettinger 691d80532b Make sets and deques weak referencable. 2004-05-30 07:26:47 +00:00
Raymond Hettinger 3fd500b4a5 The copy module now handles sets directly. The __copy__ methods are no
longer needed.
2004-03-08 18:31:10 +00:00
Raymond Hettinger a3b11e7fb3 * Simplify and speedup logic for tp_print.
* Speed-up intersection whenever PyDict_Next can be used.
2003-12-31 14:08:58 +00:00
Raymond Hettinger 81ad32e435 Speedup set.update by using the override mode for PyDict_Merge(). 2003-12-15 21:16:06 +00:00
Raymond Hettinger fb4e33a8e2 Improve algorithm for set.difference when the input is not a set. 2003-12-15 13:23:55 +00:00
Raymond Hettinger 438e02dfc8 * Refactor set.__contains__()
* Use Py_RETURN_NONE everywhere.
* Fix-up the firstpass check for the tp_print slot.
2003-12-13 19:38:47 +00:00
Raymond Hettinger 0deab62704 Refactor set.discard() and set.remove(). 2003-12-13 18:53:18 +00:00
Raymond Hettinger dc5ae11abf Use dictionary specific looping idiom where possible.
Simplifies and speeds-up the code.
2003-12-13 14:46:46 +00:00
Raymond Hettinger 8f5cdaa784 * Added a new method flag, METH_COEXIST.
* Used the flag to optimize set.__contains__(), dict.__contains__(),
  dict.__getitem__(), and list.__getitem__().
2003-12-13 11:26:12 +00:00
Raymond Hettinger bc0f2ab9bb Expose dict_contains() and PyDict_Contains() with is about 10% faster
than PySequence_Contains() and more clearly applicable to dicts.

Apply the new function in setobject.c where __contains__ checking is
ubiquitous.
2003-11-25 21:12:14 +00:00
Raymond Hettinger a38123e2fa Factor out more duplicate code. 2003-11-24 22:18:49 +00:00