IntervalMap: Containers for intervals, with efficient search.

[ bsd3, data, library ] [ Propose Tags ] [ Report a vulnerability ]

Ordered containers of intervals, with efficient search for all keys containing a point or overlapping an interval. See the example code on the home page for a quick introduction.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.2.0, 0.2.1, 0.2.2, 0.2.3, 0.2.3.1, 0.2.3.2, 0.2.3.3, 0.3.0.0, 0.3.0.1, 0.3.0.2, 0.3.0.3, 0.4.0.0, 0.4.0.1, 0.4.1.0, 0.4.1.1, 0.5.0.0, 0.5.0.1, 0.5.1.0, 0.5.1.1, 0.5.2.0, 0.5.3.1, 0.6.0.0, 0.6.1.0, 0.6.1.1, 0.6.1.2, 0.6.2.0, 0.6.2.1
Change log changelog
Dependencies base (>=4 && <5), containers, deepseq [details]
Tested with ghc ==8.0.2, ghc ==8.2.1, ghc ==8.4.1, ghc ==8.6.5, ghc ==8.8.3, ghc ==9.0.2
License BSD-3-Clause
Copyright 2011-2020 Christoph Breitkopf
Author Christoph Breitkopf
Maintainer Christoph Breitkopf <chbreitkopf@gmail.com>
Category Data
Home page http://www.chr-breitkopf.de/comp/IntervalMap
Bug tracker mailto:chbreitkopf@gmail.com
Source repo head: git clone https://github.com/bokesan/IntervalMap
Uploaded by ChristophBreitkopf at 2023-06-06T08:21:53Z
Distributions LTSHaskell:0.6.2.1, NixOS:0.6.2.1, Stackage:0.6.2.1
Reverse Dependencies 7 direct, 3 indirect [details]
Downloads 26931 total (102 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2023-06-06 [all 1 reports]

Readme for IntervalMap-0.6.2.1

[back to package description]

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](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")]