Questions tagged [finger-tree]

A finger tree is a purely functional tree data structure that gives amortized constant time access to "finger" (leaves) of the tree. Primarily used in efficiently implementing other functional data structures.

A finger tree is a purely functional data structure used in efficiently implementing other functional data structures. A finger tree gives amortized constant time access to the "fingers" (leaves) of the tree, where data is stored, and also stores in each internal node the result of applying some associative operation to its descendants. This "summary" data stored in the internal nodes can be used to provide the functionality of data structures other than trees. For example, a priority queue can be implemented by labeling the internal nodes by the minimum priority of its children in the tree, or an indexed list/array can be implemented with a labeling of nodes by the count of the leaves in their children.

Finger trees can provide amortized O(1) pushing, reversing, popping, O(log n) append and split; and can be adapted to be indexed or ordered sequences. And like all functional data structures, it is inherently persistent; that is, older versions of the tree are always preserved.

http://en.wikipedia.org/wiki/Finger_tree

16 questions
29
votes
1 answer

What should I use Clojure's finger trees for?

Clojure's new contrib library group has a finger tree library. What are the use cases for finger trees in clojure? When should finger trees be used instead of one of clojure's other peristent data strucures: vectors, sets, maps, persistentqueues,…
Rob Lachlan
  • 14,289
  • 5
  • 49
  • 99
20
votes
0 answers

How can (<*) be implemented optimally for sequences?

The Applicative instance for Data.Sequence generally performs very well. Almost all the methods are incrementally asymptotically optimal in time and space. That is, given fully forced/realized inputs, it's possible to access any portion of the…
dfeuer
  • 48,079
  • 5
  • 63
  • 167
15
votes
3 answers

Why aren't FingerTrees used enough to have a stable implementation?

A while ago, I ran across an article on FingerTrees (See Also an accompanying Stack Overflow Question) and filed the idea away. I have finally found a reason to make use of them. My problem is that the Data.FingerTree package seems to have a little…
John F. Miller
  • 26,961
  • 10
  • 71
  • 121
13
votes
2 answers

How fast is Data.Sequence.Seq compared to []?

Clearly Seq asymptotically performs the same or better as [] for all possible operations. But since its structure is more complicated than lists, for small sizes its constant overhead will probably make it slower. I'd like to know how much, in…
Petr
  • 62,528
  • 13
  • 153
  • 317
9
votes
2 answers

Finding the Missing 'Reduce' Typeclass from Finger Tree Article

Yesterday's Wikibender that started with this stackoverflow qestion on Comonads ended up at MarkCC's article on Finger Trees. In the article he makes extensive use of the Reduce type class. He writes about this typeclass as if it is a very common…
John F. Miller
  • 26,961
  • 10
  • 71
  • 121
7
votes
1 answer

Type error when implementing finger trees

I wanted to play around with 2-3 finger trees as described in the (Haskell) paper by Hinze (see also this blog). type Node<'a> = | Node2 of 'a * 'a | Node3 of 'a * 'a * 'a static member OfList = function | [a; b] -> Node2(a, b) …
primfaktor
  • 2,831
  • 25
  • 34
7
votes
1 answer

Clojure finger trees and flexvec

I am looking for a persistent sequential datastructure that allows efficient random insertions and deletions. I found the following implementations: clojure.data.finger-tree (the counted-double-list implementation) wgjo.data.cljs flexvec Since…
Inshallah
  • 4,804
  • 28
  • 24
6
votes
2 answers

Is there a simple way to implement a fast priority queue in Haskell?

I've googled a bit and found a paper on Finger Trees, which can be used to implement a priority queue with proper asymptotic complexity, but they're quite complicated, but still about the simplest thing I could find. Is there a simple data structure…
5
votes
1 answer

String representations: improvements over ropes?

I want a representation for strings with fast concatenation and editing operations. I have read the paper "Ropes: an Alternative to Strings", but have there been any significant improvements in this area since 1995? EDIT: One possibility I've…
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
3
votes
3 answers

Is there an implementation of a binary search tree annotated with sub-tree size

I have been researching the tree data structure described at this link (near the bottom): http://sigpipe.macromates.com/2009/08/13/maintaining-a-layout/ It is mentioned that this data structure could be a finger tree. However, after more research…
2
votes
1 answer

Fingertree head complexity

I was just reading Apfelmus' excellent introduction to Finger Trees for the second time and started to wonder about his implementation of head: import Prelude hiding (head) data Tree v a = Leaf v a | Branch v (Tree v a) (Tree v…
Fabian Schneider
  • 799
  • 1
  • 13
  • 40
1
vote
1 answer

Priority queue with O(1) delete-max, insert-min, and find-min and O(log n) insertion and deletion

Is it possible for monotonic priority queue to have : O(1) for finding and delete item with highest priority, O(1) for inserting item assuming the priority given is lower than every other item, O(log n) for inserting and deleting item without…
Xwtek
  • 1,151
  • 1
  • 9
  • 19
1
vote
2 answers

Data.Sequence.Seq lazy parallel Functor instance

I need parallel (but lazy) version of fmap for Seq from Data.Sequence package. But package doesn't export any Seq data constructors. So I can't just wrap it in newtype and implement Functor directly for the newtype. Can I do it without rewriting the…
Netsu
  • 355
  • 4
  • 13
1
vote
1 answer

Haskell: Where can I find the other operations from the finger tree paper?

The Finger Tree paper: http://www.soi.city.ac.uk/~ross/papers/FingerTree.html is the basis for the Data.Sequence library: https://www.haskell.org/ghc/docs/7.6.1/html/libraries/containers-0.5.0.0/Data-Sequence.html#g:10 But the library only seems to…
dspyz
  • 5,280
  • 2
  • 25
  • 63
0
votes
1 answer

Q: Optimized data structure for Branched and Versioned entities

Given an entity (say a file or a library/package) that can evolve its versions and branches over time, looking for a optimized data structure that lets me navigate through the versions to a specific instance of the entity. For example (a bit…
V P
  • 845
  • 10
  • 28
1
2