3 releases

0.1.5 Oct 12, 2023
0.1.4 Jun 19, 2023
0.1.3 Sep 18, 2022

#1805 in Data structures

Download history 117/week @ 2024-07-25 291/week @ 2024-08-01 141/week @ 2024-08-08 195/week @ 2024-08-15 224/week @ 2024-08-22 181/week @ 2024-08-29 139/week @ 2024-09-05 193/week @ 2024-09-12 190/week @ 2024-09-19 163/week @ 2024-09-26 217/week @ 2024-10-03 106/week @ 2024-10-10 232/week @ 2024-10-17 244/week @ 2024-10-24 204/week @ 2024-10-31 85/week @ 2024-11-07

788 downloads per month

MIT license

16KB
386 lines

Segmentmap

A generic collection that preserves the order of items at all cost. Removing an item never restructures, keys/indices are unique per item. Internally uses a HashMap of arrays containing the items. Also tested with an internal BTreeMap, but results were worse. Iterator is stable, using a linked-list-like structure.

Using an array size >128 makes the segmentmap significantly slower when inserting (>10%). Similar when you use a small array size (like 16). The smaller the array, the more similar it is to an indexmap, The larger the array, the more similar it is to an array (duh). (but in both cases it will still preserve order when removing, without restructuring).

More of a PoC than something you should start using.

Benchmarking

These are the results of some very basic benchmarking I did (cargo run) against common collections. Listed are the durations of doing 1 million operations sequentially, so to get the average just divide by 1M.

type adding 1M iterating over 1M deleting 1M sequentially
SegmentMap 654.97ms 305.44ms 312.97ms
HashMap 983.93ms 37.15ms 579.11ms
BTreeMap 2.48s 97.58ms 1.07s
Vec 36.67ms 17.45ms 10.25s

Dependencies

~72KB