ArrayDeques and How to Contribute to Scala 2.13 Collections
summary
Scala 2.13 adds a mutable ArrayDeque implemented as a circular array with start/end pointers that gives constant-time prepend/append/get and O(min(i, n-i)) insert/delete at index, using at most two memcpy copies on resize and a bit trick when capacity is power-of-two. Benchmarks (ref-tree visuals and GitHub code) show prepends that take milliseconds versus seconds for ArrayBuffer when growing to 10 million items. API includes both clear and clearAndShrink. Source, diagrams and benchmarks are on the linked repo.
AI-written summary · about
chapters (7)
- 0:00Start
- 4:06New Collections
- 7:14Insert and Deletes
- 18:16Source Code
- 19:21Pre-Emptive Allocations of the Correct Size
- 20:42Benchmarks
- 22:54Takeaways
related talks
23mArrayDeques and How to Contribute to Scala 2.13
39mExtreme Cleverness: Functional Data Structures in Scala
51mImplementing the Scala 2.13 collections
37mWhat’s in the next iteration of the standard collections?
54mHow Not to Write Slow Scala
35mMigrating to Scala 2.13
42mWhat Scala can learn from Rust, Swift, and C++
28mRust and Scala, Sitting in a Tree….
