coalesce ( alist -- specification )
Factor handbook » The language » Collections » Interval maps

Prev:<interval-map> ( specification -- map )


Vocabulary
interval-maps

Inputs
alistan association list with integer keys


Outputs
specificationarray of the format used by <interval-map>


Word description
Finds ranges used in the given alist, coalescing them into a single range.

Definition


:: coalesce ( alist -- specification )
[
alist sort-keys unclip swap [ first2 dupd ] dip [|
oldkey oldval key val |
oldkey 1 + key = oldval val = and
[ oldkey 2array oldval 2array , key ] unless key val
] assoc-each [ 2array ] bi@ ,
] { } make ;