[Python-ideas] set.add(x) slower than if x in set:set.add(x)

Daniel Stutzbach daniel at stutzbachenterprises.com
Mon Sep 14 16:26:04 CEST 2009


On Mon, Sep 14, 2009 at 9:19 AM, Gerald Britton <gerald.britton at gmail.com>wrote:

> assuming that set.add() takes close to the same time whether the item
> is in the set or not (in reality I suppose that it needs to play with
> a few pointers if the item is not in the set and may need to rebalance
> the tree, if it is a red-black tree or something similar -- what is
> it, actually?)
>

Under the hood, the set type uses a hash table.

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090914/1238d388/attachment.html>


More information about the Python-ideas mailing list