PrimitiveArray-0.6.1.0: Efficient multidimensional arrays

Safe HaskellNone
LanguageHaskell2010

Data.PrimitiveArray.Index.Subword

Description

Index structure for context-free grammars on strings. A Subword captures a pair (i,j) with i<=j.

Synopsis

Documentation

newtype Subword Source

A subword wraps a pair of Int indices i,j with i<=j.

Subwords always yield the upper-triangular part of a rect-angular array. This gives the quite curious effect that (0,N) points to the ``largest'' index, while (0,0) ... (1,1) ... (k,k) ... (N,N) point to the smallest. We do, however, use (0,0) as the smallest as (0,k) gives successively smaller upper triangular parts.

Constructors

Subword 

Fields

fromSubword :: Int :. Int
 

triangularNumber :: Int -> Int Source

triangular numbers

A000217

upperTri :: Subword -> Int Source

Size of an upper triangle starting at i and ending at j. "(0,N)" what be the normal thing to use.

subwordIndex :: Subword -> Subword -> Int Source

Subword indexing. Given the longest subword and the current subword, calculate a linear index "[0,..]". "(l,n)" in this case means "l"ower bound, length "n". And "(i,j)" is the normal index.

TODO probably doesn't work right with non-zero base ?!