All Projects → namenu → data.deque

namenu / data.deque

Licence: other
Persistent Deque for Clojure(Script)

Programming Languages

clojure
4091 projects

Labels

Projects that are alternatives of or similar to data.deque

Javascript Datastructures Algorithms
📚 collection of JavaScript and TypeScript data structures and algorithms for education purposes. Source code bundle of JavaScript algorithms and data structures book
Stars: ✭ 3,221 (+4568.12%)
Mutual labels:  deque
py-algorithms
Algorithms and Data Structures, solutions to common CS problems.
Stars: ✭ 26 (-62.32%)
Mutual labels:  deque
deque
JavaScript implementation of a double-ended queue
Stars: ✭ 17 (-75.36%)
Mutual labels:  deque
deque
A highly optimized double-ended queue
Stars: ✭ 75 (+8.7%)
Mutual labels:  deque
quetie
🎀 Just the cutest and tiniest queue/deque implementation!
Stars: ✭ 111 (+60.87%)
Mutual labels:  deque
ctl
My variant of the C Template Library
Stars: ✭ 105 (+52.17%)
Mutual labels:  deque

data.deque

Clojars Project

data.deque is a persistent deque for Clojure(Script). Deque(double-ended queue) is an abstract data type that generalizes a queue, for which elements can be added to or removed from either the front or back.

The implementation of data.deque is based on a slightly modified version of Finger tree. It gives O(1) access to both ends and amortized O(1) for immutable insertion/deletion.

Example

(require '[data.deque :as dq])

;; create an empty deque with `(deque)` or
(def dl (dq/deque 5 4 3 2 1))

(dq/peek-first dl)
;=> 1

(dq/peek-last dl)
;=> 5

(-> dl
    (dq/add-first 0)
    (dq/add-last 6)
    seq)
;=> (0 1 2 3 4 5 6)

(-> dl
    (dq/remove-first)
    (dq/remove-last)
    seq)
;=> (2 3 4)

Differences from core.data.finger-tree

  • ClojureScript support
  • Better performance
  • No unnecessary features for deque
    • Trees are not concatable / splittable
    • No measuring interfaces

Benchmark

implementation small medium large rate
java.util.ArrayDeque (base) 37.94ms 271.44ms 3.47s x1
clojure.data.finger-tree 196.50ms 1.23s 12.88s x3.86
data.deque (JVM) 158.50ms 595.49ms 6.13s x1.89
data.deque (Browser) 152ms 807ms 7.47s x2.31
  • Tested on 2.8 GHz Quad-Core Intel Core i7

Why Finger Tree?

Banker's Deque is also a purely functional data structure that guarantee amortized constant time but performs worse due to reverse operation. Real-Time Deque eliminates amortization by "Lazy Rebuilding" technique, but it also has some overhead due to its laziness. Finger Tree provides a balanced framework for building deque in terms of both time and space complexity.

Reference

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].