I tried googling for this but all I got were stories about minor celebrities. Given the lack of documentation, what is a DList?
相关问题
- Unusual use of the new keyword
- how to split a list into a given number of sub-lis
- C#: How do i get 2 lists into one 2-tuple list in
- Get Runtime Type picked by implicit evidence
- F#: Storing and mapping a list of functions
相关文章
- List可以存储接口类型的数据吗?
-
C# List
.FindAll 时 空指针异常 - Gatling拓展插件开发,check(bodyString.saveAs("key"))怎么实现
- RDF libraries for Scala [closed]
- What is the complexity of bisect algorithm?
- Why is my Dispatching on Actors scaled down in Akk
- Given a list and a bitmask, how do I return the va
- How do you run cucumber with Scala 2.11 and sbt 0.
It's a data type in the non-canonical scalaz package, useful for typed lists with constant-time access at both ends. (The trick is to google for "scala" AND "dlist".)
Difference lists are a list-like data structure that supports O(1) append operations.
Append, and other operations that modify a list are represented via function composition of the modification functions, rather than directly copying the list.
An example, from Haskell's dlist library:
The technique goes back at least to Hughes 84, A novel representation of lists and its application to the function "reverse", R. John Hughes, 1984., where, he proposes representing lists as functions, and append as function composition, allowing e.g. reverse to run in linear time. From the paper:
From the project page of scalaz:
It's a Difference List, along the lines of "Difference List as functions"
Efficient prepending:
Inefficient appending. This creates an intermediate list (l1 ++ l2), then ((l1 ++ l2) ++ l3)
DList
stores up the appends, and only needs to create one complete list, effectively invoking: