IntervalMap Hackage Build Status

Containers for intervals. Like Data.Set and Data.Map with Intervals as keys and functions for efficiently getting the subset of all intervals containing a point, intersecting an interval, and more.

Home page and documentation: http://www.chr-breitkopf.de/comp/IntervalMap/index.html

Getting started

Enable necessary language extensions:

{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}

In most cases, you should use the value-strict version:

import qualified Data.IntervalMap.Generic.Strict as IM

Make tuples an instance of Interval:

instance Ord e => IM.Interval (e,e) e where
    lowerBound (a,_) = a
    upperBound (_,b) = b
    rightClosed _ = False

By using rightClosed _ = False we have defined tuples to be half-open intervals - they include the starting value, but not the end value.

Let’s create a map from (Int,Int) intervals to strings:

type MyMap = IM.IntervalMap (Int,Int) String

sample :: MyMap
sample = IM.fromList [((1,6), "Foo"), ((2,4), "Bar"), ((4,7), "Baz")]

Lookup intervals containing a given point (“stabbing query”):

> IM.toAscList (sample `IM.containing` 3)
[((1,6),"Foo"),((2,4),"Bar")]
> IM.toAscList (sample `IM.containing` 4)
[((1,6),"Foo"),((4,7),"Baz")]

Changes

0.6.1.0 Add safe versions of find... functions.

0.6.0.0 Support ghc 8.4, desupport ghc 7.x.

0.5.3.1 Remove HPC flag.
0.5.3.0 Add lookupLT... functions.

0.5.2.0 Bugfix: exported Prelude functions instead of correct ones.

0.5.1.1 Improve performance of findLast.

0.5.1.0 Major performance improvements.

0.5.0.1 Improve performance of combine.
Fix wrong doc comments.

0.5.0.0 Change return type of containing, ... to a map.
Add splitAt, splitIntersecting, flatten... functions.
Minor performance tweaks.

0.4.1.1 Fix bug in benchmark.

0.4.1.0 Add IntervalSet.
Minor performance tweaks.
Documentation updates.
Moved to GitHub.

0.4.0.1 Documentation update. Wrong portability info fixed.

0.4.0.0 Major update adding support for user-defined key intervals.

0.3.0.3 Updated benchmark to use Criterion 1.0. Tested with ghc 7.8.3.

0.3.0.2 Dropped upper constraint on criterion. Tested with ghc 7.6.3.
Migrated repo to Darcs Hub.

0.3.0.1 Bugfixes: Lazy was too strict, Strict too lazy.

0.3.0.0 Split into Lazy and Strict modules, following containers.

Depends on 3 packages:
comments powered byDisqus