scala> import spire.math._
import spire.math._
scala> import spire.implicits._
import spire.implicits._
scala> Interval.empty[Long]
res1: spire.math.Interval[Long] = (Ø)
scala> Interval.empty[Long] union Interval.point(1L)
res2: spire.math.Interval[Long] = [1]
scala> Interval.empty[Long] union Interval.above(1L)
res3: spire.math.Interval[Long] = (0, ∞)
On Mon, Dec 22, 2014 at 12:48:51AM +0100, Rüdiger Klaehn wrote:
> Just in case you are wondering why I am using intervals so heavily: I
> have written a data structure for non-overlapping interval sets of
> primitive types: https://github.com/rklaehn/intervalset
>
> It is very fast and efficiently supports all operations that you need
> to define a boolean algebra (and, or, not, xor). The downside is of
> course that it only works for things that can be converted into a long
> while preserving order.
>
> I will try if I can write something with acceptable performance that
> does not have this limitation, but it will never be as fast.
>
> Would you be interested in having something like this in spire? I
> think it would make a nice addition.
Hi Rüdiger,
That looks really interesting! I'd love to have something like that
available in Spire, either in a subproject or in core. Please keep me
posted on your progress with making the sets generic -- it would be
great if they were able to support SafeLong as well (although of
course I understand the performance concerns).
$ sbt console
scala> import IntervalSeq._
import IntervalSeq._
scala> (above(Rational(1,3)) | below(Rational(-4,7))) ^ point(Rational(17,5))
res0: com.rklaehn.interval.IntervalSeq[spire.math.Rational] = (-∞, -4/7);(1/3, 17/5);(17/5, ∞)
scala> ~res0
res1: com.rklaehn.interval.IntervalSeq[spire.math.Rational] = [-4/7, 1/3];[17/5]
scala>
It would be good to be
able to put a number on the speed penalty: is it 2x slower? 5x?