<div dir="ltr"><br>On Tuesday, February 28, 2017 at 6:48:42 PM UTC-5, 语言破碎处 wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div>> A hypothetical frozenset.pop() is also necessarily O(N).  It needs to 
copy N-1 elements into the new (smaller) frozenset object.  So this 
isn't an argument.<br>Pop tuple/frozenset(standard one) gain no benefit. # O(n)<br>It is a different story for balanced tree. # O(log n)<br></div><br><div>> Sounds like `collections.deque` might be what you want (for concurrency,
 not for immutability).  But a local copy will require, by definition, a
 *copy* operation either way.<br>My intent is to unify "SET" interface, not for to using deque.<br>     I want something that is SET can use anywhere regardless mutable or not.<br>    <span style="display:none;width:0px;min-height:0px"></span>And the idiom SHOULD work for other type.<br><br>WHY set.add / list.sort return None?<br>     if return self,  someone may think it don't modify the orignal object.<br>     so, mutable object will have different methods.<br>Such differences are good UNLESS we want to ignore it explictly.<br>We need a uniform way to make a interface suitable for both cases. <br><br></div></div></blockquote><div><br></div><div>collections.abc.Set is the uniform interface suitable for mutable and immutable sets:</div><div><br></div><div>https://docs.python.org/3/library/collections.abc.html<br></div><div><br></div><div>It contains:</div><div><br>__contains__, __iter__, __len__ __le__, __lt__, __eq__, __ne__, __gt__, __ge__, __and__, __or__, __sub__, __xor__, and isdisjoint<br></div><div><br></div><div>Is there something missing?  I don't think add should be there. I think if you want to start mutating a (possibly immutable)  set, you should convert it to set (pay the linear cost up-front) and then start mutating it.</div><div><br></div><blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><br><div style="zoom:1"></div><div></div><br>At 2017-03-01 07:14:33, "David Mertz" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="Tbot091rEAAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">me...@gnosis.cx</a>> wrote:<br> <blockquote style="PADDING-LEFT:1ex;MARGIN:0px 0px 0px 0.8ex;BORDER-LEFT:#ccc 1px solid"><div dir="ltr"><div><div class="gmail_quote">On Tue, Feb 28, 2017 at 2:57 PM, 语言破碎处 <span dir="ltr"><<a href="javascript:" target="_blank" gdf-obfuscated-mailto="Tbot091rEAAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">mlet_...@126.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><span><div>1) coverting to set or list is O(n) in time<br></div></span></div></blockquote><div><br></div><div>A hypothetical frozenset.pop() is also necessarily O(N).  It needs to copy N-1 elements into the new (smaller) frozenset object.  So this isn't an argument.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><span><div></div></span><div>2) if I have to keep the old copy,<br>    standard set solution will be O(n) both in time and space!<br></div></div></blockquote><div><br></div><div>Again, nothing gained here. Same applies to frozenset.pop() (assuming it returns both the item popped and a reduced set).  If you just want "something from frozenset" without creating a new almost-copy frozenset, that is spelled `next(iter(fs))`.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div>working examples:<br>    1) priority queue:<br>        insert and pop occur<br>    2) share immutable data to difference subroutines:<br>        each one can modify local copy safely and concurrency.<br></div></div></blockquote><div><br></div><div>Sounds like `collections.deque` might be what you want (for concurrency, not for immutability).  But a local copy will require, by definition, a *copy* operation either way. </div></div><br clear="all"><div><br></div>-- <br><div>Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</div></div>
</blockquote></div><br><br><span title="neteasefooter"><p> </p></span></blockquote></div>