GithubHelp home page GithubHelp logo

shadowkun / indexmap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from indexmap-rs/indexmap

0.0 1.0 0.0 730 KB

A hash table with consistent order and fast iteration; access items by key or sequence index

Home Page: https://docs.rs/indexmap/

License: Other

Rust 100.00%

indexmap's Introduction

indexmap

build status crates.io docs rustc

A pure-Rust hash table which preserves (in a limited sense) insertion order.

This crate implements compact map and set data-structures, where the iteration order of the keys is independent from their hash or value. It preserves insertion order (except after removals), and it allows lookup of entries by either hash table key or numerical index.

Note: this crate was originally released under the name ordermap, but it was renamed to indexmap to better reflect its features.

Background

This was inspired by Python 3.6's new dict implementation (which remembers the insertion order and is fast to iterate, and is compact in memory).

Some of those features were translated to Rust, and some were not. The result was indexmap, a hash table that has following properties:

  • Order is independent of hash function and hash values of keys.
  • Fast to iterate.
  • Indexed in compact space.
  • Preserves insertion order as long as you don't call .remove().
  • Uses hashbrown for the inner table, just like Rust's libstd HashMap does.

Performance

IndexMap derives a couple of performance facts directly from how it is constructed, which is roughly:

A raw hash table of key-value indices, and a vector of key-value pairs.

  • Iteration is very fast since it is on the dense key-values.

  • Removal is fast since it moves memory areas only in the table, and uses a single swap in the vector.

  • Lookup is fast-ish because the initial 7-bit hash lookup uses SIMD, and indices are densely stored. Lookup also is slow-ish since the actual key-value pairs are stored separately. (Visible when cpu caches size is limiting.)

  • In practice, IndexMap has been tested out as the hashmap in rustc in PR45282 and the performance was roughly on par across the whole workload.

  • If you want the properties of IndexMap, or its strongest performance points fits your workload, it might be the best hash table implementation.

Recent Changes

See RELEASES.md.

indexmap's People

Contributors

bluss avatar cuviper avatar mwillsey avatar linclelinkpart5 avatar thermatix avatar mingun avatar overvenus avatar snektron avatar taiki-e avatar kamilaborowska avatar lucab avatar mexus avatar pczarn avatar mbrubeck avatar dtolnay avatar bhgomes avatar rouge8 avatar hcpl avatar bjorn3 avatar zakcutner avatar techcable avatar stepancheg avatar razican avatar binero avatar kjeremy avatar jakobdegen avatar weiznich avatar erickt avatar striezel avatar kaduo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.