Jonathan Eunice avatar Jonathan Eunice committed 52e952a

fixed and tested issue with pop() on PyPy

Comments (0)

Files changed (4)

-Subset of ``set`` designed to conveniently hold sets of integers. It 
-creates them from, and displays them as, 
-integer spans (e.g. ``1-3,14,29,92-97``). When iterating over an ``intspan``,
-iteration is ordered. 
+Subset of ``set`` designed to conveniently hold sets of integers. It creates
+them from, and displays them as, integer spans (e.g. ``1-3,14,29,92-97``). When
+iterating, ``pop()``-ing an item, or converting to a list, ``intspan`` behaves as
+if it were an ordered collection. 
 
 The main draw is that this provides a convenient way
 to specify ranges--for example, ranges of rows to be processed in a spreadsheet.
 
-
 Usage
 =====
 
 optimized for long contiguous runs. For sets of several hundred or thousand
 members, you will probably never notice the difference.
 
-On the other hand, if you're dealing
-with large sets (e.g. with 10,000 or more elements), or doing lots of set operations
+On the other hand, if you're doing lots of processing of
+large sets (e.g. with 100,000 or more elements), or doing lots of set operations
 on them (e.g. union, intersection), a data structure based on
 lists of ranges, `run length encoding
 <http://en.wikipedia.org/wiki/Run-length_encoding>`_, or `Judy arrays
 Alternatives
 ============
 
-There are several generally available modules you might want to consider as
-alternatives or supplements. None of them provide (AFAIK) the convenient
+There are several modules you might want to consider as
+alternatives or supplements. AFAIK, none of them provide the convenient
 integer span specification that ``intspan`` does, but they have other virtues:
 
  *  `cowboy <http://pypi.python.org/pypi/cowboy>`_ provides
 
  *  Some ``set`` operations such as ``update()``, ``add()``, ``discard()``, and
     ``remove()`` take integer span strings as arguments. In some cases this
-    changes a method that took one item into one that takes multiple. Not all
+    changes a method that took one item into one that takes multiple. They may
+    also take string specifications of intspans that are not proper ``intspan``
+    objects. But it's not perfectly uniform, and not all
     ``set`` operations have been so extended.
     
  *  String representation based on Jeff Mercado's concise answer to `this
         """
         return iter(sorted(super(intspan, self).__iter__()))
     
+    def pop(self):
+        min_item = min(self)
+        self.discard(min_item)
+        return min_item
+    
+        # this method required only for PyPy, which otherwise gets the wrong
+        # answer (unordered)
+    
     @staticmethod
     def _parse_range(datum):
         if isinstance(datum, basestring):
 
 setup(
     name='intspan',
-    version=verno("0.5"),
+    version=verno("0.504"),
     author='Jonathan Eunice',
     author_email='jonathan.eunice@gmail.com',
     description="Sets of integers like 1,3-7,33. Inspired by Perl's Set::IntSpan",

test/test_intspan.py

     assert s == intspan('10-15,50-55')
     s ^= intspan('10,99')
     assert s == intspan('11-15,50-55,99')
+    
+def test_pop():
+    s = intspan('100-110')
+    assert s.pop() == 100
+    assert s.pop() == 101
+    assert s.pop() == 102
+    assert s.pop() == 103
+    assert s.pop() == 104
+    assert s.pop() == 105
+    assert s == intspan('106-110')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.