Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate augmenting RawTable directly #30

Closed
apasel422 opened this issue Oct 1, 2015 · 6 comments
Closed

Investigate augmenting RawTable directly #30

apasel422 opened this issue Oct 1, 2015 · 6 comments
Milestone

Comments

@apasel422
Copy link
Contributor

This crate wraps HashMap to provide ordered iteration with very little additional code, but its approach is essentially a hack and requires additional heap allocation in order to work. We should consider augmenting RawTable with a type parameter in order to implement this more efficiently. Normal HashMaps would use () internally for this parameter, while LinkedHashMap would use a struct Link { next: usize, prev: usize }.

CC @gankro.

@Gankra
Copy link
Contributor

Gankra commented Oct 2, 2015

As in you want upstream to expose RawTable?

@apasel422
Copy link
Contributor Author

More like having std itself provide LinkedHashMap instead of hacking on top of it as this crate currently does.

@apasel422
Copy link
Contributor Author

What I want to do here is define RawTable as:

struct RawTable<K, V, A = ()> {
    capacity: usize,
    size: usize,
    hashes: Unique<u64>, // dynamic allocation of `cap` `u64`s | `cap` `K`s | `cap` `V`s | `cap` `A`s
    aug: A, // used to store the head/tail indices for the linked version
    marker: marker::PhantomData<(K, V)>,
}

and then

struct Link {
    next: usize,
    prev: usize,
}

pub struct LinkedHashMap<K, V> {
    table: RawTable<K, V, Link>,
    ...
}

This will let us remove the extra key/value indirection in the current impl along with the dummy node, though the performance implications remain to be determined.

@Gankra
Copy link
Contributor

Gankra commented Oct 7, 2015

Forking std's impl seems more viable, honestly.

@apasel422
Copy link
Contributor Author

I think we should look into this, even if it involves maintaining an internal copy of RawTable for the time being.

CC @carllerche.

@apasel422 apasel422 added this to the 1.0 milestone Apr 22, 2016
@carllerche
Copy link
Contributor

To follow up, I extracted the hash table as a standalone library that runs on stable Rust. https://github.com/carllerche/hash-table

@Gankra Gankra closed this as completed Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants