3131from itertools import count
3232from itertools import groupby
3333
34- from intbitset import intbitset
34+ try :
35+ from intbitset import intbitset
36+
37+ spanset = intbitset
38+ except :
39+ spanset = set
40+
3541
3642"""
3743Ranges and intervals of integers using bitmaps.
@@ -99,24 +105,24 @@ def __init__(self, *args):
99105 len_args = len (args )
100106
101107 if len_args == 0 :
102- self ._set = intbitset ()
108+ self ._set = spanset ()
103109
104110 elif len_args == 1 :
105111 # args0 is a single int or an iterable of ints
106112 if isinstance (args [0 ], int ):
107- self ._set = intbitset (args )
113+ self ._set = spanset (args )
108114 else :
109115 # some sequence or iterable
110- self ._set = intbitset (list (args [0 ]))
116+ self ._set = spanset (list (args [0 ]))
111117
112118 elif len_args == 2 :
113119 # args0 and args1 describe a start and end closed range
114- self ._set = intbitset (range (args [0 ], args [1 ] + 1 ))
120+ self ._set = spanset (range (args [0 ], args [1 ] + 1 ))
115121
116122 else :
117123 # args0 is a single int or args is an iterable of ints
118124 # args is an iterable of ints
119- self ._set = intbitset (list (args ))
125+ self ._set = spanset (list (args ))
120126
121127 @classmethod
122128 def _from_iterable (cls , it ):
@@ -211,9 +217,9 @@ def __contains__(self, other):
211217 return self ._set .__contains__ (other )
212218
213219 if isinstance (other , (set , frozenset )):
214- return self ._set .issuperset (intbitset (other ))
220+ return self ._set .issuperset (spanset (other ))
215221
216- if isinstance (other , intbitset ):
222+ if isinstance (other , spanset ):
217223 return self ._set .issuperset (other )
218224
219225 @property
@@ -230,12 +236,16 @@ def issuperset(self, other):
230236 def start (self ):
231237 if not self ._set :
232238 raise TypeError ("Empty Span has no start." )
239+ if isinstance (self ._set , set ):
240+ return sorted (self ._set )[0 ]
233241 return self ._set [0 ]
234242
235243 @property
236244 def end (self ):
237245 if not self ._set :
238246 raise TypeError ("Empty Span has no end." )
247+ if isinstance (self ._set , set ):
248+ return sorted (self ._set )[- 1 ]
239249 return self ._set [- 1 ]
240250
241251 @classmethod
0 commit comments