#set-operations #immutability #set #map #persistent #functional

no-std immutable-chunkmap

A fast immutable map and set with batch insert and update methods, COW operations, and big O efficient implementations of set and merge operations

31 releases (13 stable)

2.0.6 Oct 21, 2024
2.0.5 May 20, 2024
2.0.4 Feb 4, 2024
2.0.2 Oct 23, 2023
0.1.2 Dec 26, 2017

#108 in Data structures

Download history 10425/week @ 2024-07-18 16476/week @ 2024-07-25 15421/week @ 2024-08-01 17182/week @ 2024-08-08 16965/week @ 2024-08-15 18878/week @ 2024-08-22 19636/week @ 2024-08-29 21627/week @ 2024-09-05 21364/week @ 2024-09-12 23079/week @ 2024-09-19 29199/week @ 2024-09-26 29996/week @ 2024-10-03 30115/week @ 2024-10-10 34985/week @ 2024-10-17 36366/week @ 2024-10-24 40886/week @ 2024-10-31

147,657 downloads per month
Used in 492 crates (5 directly)

Apache-2.0 OR MIT

150KB
4K SLoC

immutable chunk map

A cache efficient immutable map with lookup performance close to BTreeMap and reasonably good insertion performance. Optional copy on write mutable operations bring modification performance within 2x of BTreeMap in the best case while still offering snapshotting, and big O efficient set operations of a persistant data structure.

A graph of lookup performance of various data structures using usize keys. Full test data in the bench/charts directory. Tests performed on an Intel Core i7 8550U under Linux with a locked frequency of 1.8 GHz.

  • OCaml: core map (from the Jane Street core library), an AVL tree with distinct leaf nodes and a relaxed balance constraint.
  • Chunkmap: this library
  • Chunkmap COW: this library using only COW operations
  • BTreeMap: from the Rust standard library
  • HashMap: from the Rust standard library

alt text

Chunkmap is very close to BTreeMap for random accesses using keys without hashing. Obviously if you don't need ordered data use a HashMap.

alt text

Insertion performance, while not as good as most mutable data structures, is not awful when using COW mode exclusively. In the case where you have many updates to do at once you can go even faster by using insert_many. In some cases, e.g. building a map from scratch using sorted inputs this can be faster than even a HashMap. The below case is more typical, adding 10% of a data set to the map.

alt text

A note about the COW bar on this graph. It represents using only mutable COW operations on the map, it is perfectly possible to use an actual insert_many call instead of mutable COW operations if it's faster in your application, which as you can see, depends on the size of the map.

License

This project is dual licensed under the MIT or the Apache 2 at your discretion.

Dependencies

~63–495KB
~10K SLoC