-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bcf9e30
commit 8663aa4
Showing
2 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
## [v0.1.1] - 2022-03-29 | ||
|
||
### Added | ||
|
||
[Change log](CHANGELOG.md) | ||
|
||
### Changed | ||
|
||
[Readme](README.md) | ||
|
||
### Removed | ||
|
||
Nothign | ||
|
||
### Fixed | ||
|
||
Nothing | ||
|
||
|
||
## [v0.1.0] - 2022-03-29 | ||
|
||
### Added | ||
|
||
Initial publication. Created `DHashmap` data structure, and add some methods to it[^1]: | ||
- **`new`:** creates a new empty `DHashMap`; | ||
- **`with_capacity`:** creates an empty `DHashMap` with the specified capacity; | ||
- **`with_hasher`:** creates an empty `DHashMap` which will use the given hash builder to hash keys; | ||
- **`with_capacity_and_hasher`:** creates an empty `DHashMap` with the specified capacity, using `hash_builder` to hash the keys; | ||
- **`capacity`:** returns the number of elements the map can hold without reallocating; | ||
- **`len`:** returns the number of elements in the map.; | ||
- **`is_empty`:** returns `true` if the map contains no elements; | ||
- **`clear`:** clears the map, removing all keys-value tuples `(K1, K2, V)`. Keeps the allocated memory for reuse; | ||
- **`hasher`:** returns a reference to the map's `BuildHasher`; | ||
- **`reserve`:** reserves capacity for at least `additional` more elements; | ||
- **`try_reserve`:** tries to reserve capacity for at least `additional` more elements; | ||
- **`shrink_to_fit`:** shrinks the capacity of the map as much as possible; | ||
- **`shrink_to`:** shrinks the capacity of the map with a lower limit; | ||
- **`entry`:** tries to gets the given keys' corresponding entry in the map for in-place manipulation. Return error if primary `K1` key or secondary `K2` ***not*** both vacant or exist and refers to the same value. Given keys returned inside `error` structure. | ||
- **`get_key1`:** returns a reference to the value corresponding to the given primary key `(K1)`; | ||
- **`get_key2`:** returns a reference to the value corresponding to the given secondary key `(K2)`; | ||
- **`get_mut_key1`:** returns a mutable reference to the value corresponding to the given primary key `(K1)`; | ||
- **`get_mut_key2`:** returns a reference to the value corresponding to the given secondary key `(K2)`; | ||
- **`insert_unchecked`:** insert keys-value tuple `(K1, K2, V)` into the map ***without*** checking that primary `K1` key or secondary `K2` key vacant or exist in map and refers to the same value. | ||
- **`insert`:** insert keys-value tuple `(K1, K2, V)` into the map `(K1, K2, V)` ***with*** checking that primary `K1` key or secondary `K2` key vacant or exist in map and refers to the same value. Return error if its failure. Given keys and value returned inside `error` structure. | ||
- **`try_insert`:** tries insert keys-value tuple `(K1, K2, V)` into the map if they vacant and returning error if any of keys or both keys exist in the map. Given value or value and keys together returned inside `error` enum (depends error type). | ||
- **`remove_key1`:** remove element from map corresponding to the given primary key `(K1)`; | ||
- **`remove_key2`:** remove element from map corresponding to the given secondary key `(K2)`. | ||
[^1]: The `K1`, `K2`, `V` abbreviations means: `K1` - a primary key of type `K1`; `K2` - a secondary key of type `K2`; `V` - a value of type `K2`. | ||
|
||
### Changed | ||
|
||
Nothign | ||
|
||
### Removed | ||
|
||
Nothign | ||
|
||
### Fixed | ||
|
||
Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,95 @@ | ||
# Double-hash | ||
Double Map | ||
========== | ||
|
||
[](https://crates.io/crates/double-map) | ||
[](https://docs.rs/double-map) | ||
[](https://github.com/JustForFun88/double-map) | ||
|
||
Like a [HashMap], but allows you to use two different keys to the same value/data. | ||
|
||
Sometimes during development, it may be necessary to have a data structure like | ||
a `HashMap` but with two different keys refiring to the same data. | ||
|
||
For example, if you have some data with a unique ID and a name, then you create | ||
a structure that contains the name, and store it in a ***normal*** `HashMap` using | ||
the unique ID as the key. However, finding the element throughout the name will be | ||
performed with O(n) time. The same is true for the reverse case. | ||
|
||
This crate try to resolve this contradiction by providing a DHashMap structure - | ||
a map where you can add, lookup and remove elements using either the first key | ||
of type `K1` or the second key of type `K2`. | ||
|
||
Internally, it uses two maps: the first is of type `HashMap<K1, (K2, V)>` and | ||
the second is of type `HashMap<K2, K1>`. Using two `HashMap`'s insides instead | ||
one brings to the performance and memory penalty. | ||
|
||
It is recommended to use the first key of type `K1` of quick access to the data, | ||
because indexing by the second key of type `K2` requires two `HashMap` lookups. | ||
|
||
## [Change log](CHANGELOG.md) | ||
|
||
## Current Status | ||
|
||
Double Map is in active development. The design goal is implementing the whole [HashMap] | ||
interface. Look at [Change log](CHANGELOG.md) for more infomation. | ||
|
||
### Methods | ||
|
||
- [x] `new`: Done sinse `v0.1.0` | ||
- [x] `with_capacity`: Done sinse `v0.1.0` | ||
- [x] `with_hasher`: Done sinse `v0.1.0` | ||
- [x] `with_capacity_and_hasher`: Done sinse `v0.1.0` | ||
- [x] `capacity`: Done sinse `v0.1.0` | ||
- [ ] `keys`: Under development | ||
- [ ] `into_keys`: Under development | ||
- [ ] `values`: Under development | ||
- [ ] `values_mut`: Under development | ||
- [ ] `into_values`: Under development | ||
- [ ] `iter Under`: development | ||
- [ ] `iter_mut`: Under development | ||
- [x] `len`: Done sinse `v0.1.0` | ||
- [x] `is_empty`: Done sinse `v0.1.0` | ||
- [ ] `drain`: Under development | ||
- [ ] `drain_filter`: Under development | ||
- [ ] `retain`: Under development | ||
- [x] `clear`: Done sinse `v0.1.0` | ||
- [x] `hasher`: Done sinse `v0.1.0` | ||
- [x] `reserve`: Done sinse `v0.1.0` | ||
- [x] `try_reserve`: Done sinse `v0.1.0` | ||
- [x] `shrink_to_fit`: Done sinse `v0.1.0` | ||
- [x] `shrink_to`: Done sinse `v0.1.0` | ||
- [x] `entry`: Done sinse `v0.1.0` | ||
- [x] `get`: Done sinse `v0.1.0` (`get_key1` and `get_key2` methods) | ||
- [ ] `get_key_value`: Under development | ||
- [ ] `contains_key`: Under development | ||
- [x] `get_mut`: Done sinse `v0.1.0` (`get_mut_key1` and `get_mut_key2` methods) | ||
- [x] `insert`: Done sinse `v0.1.0` (`insert_unchecked` and `insert` methods) | ||
- [x] `try_insert`: Done sinse `v0.1.0` | ||
- [x] `remove`: Done sinse `v0.1.0` (`remove_key1` and `remove_key2` methods) | ||
- [ ] `remove_entry`: Under development | ||
- [ ] `raw_entry_mut`: Under development | ||
- [ ] `raw_entry`: Under development | ||
|
||
### Trait Implementations | ||
- [ ] `Clone`: Under development | ||
- [ ] `Debug`: Under development | ||
- [ ] `Default`: Under development | ||
- [ ] `Extend`: Under development | ||
- [ ] `From`: Under development | ||
- [ ] `FromIterator`: Under development | ||
- [ ] `Index`: Under development | ||
- [ ] `IntoIterator`: Under development | ||
- [ ] `PartialEq`: Under development | ||
|
||
## License | ||
|
||
Licensed under Apache License, Version 2.0, ([LICENSE](LICENSE) or https://www.apache.org/licenses/LICENSE-2.0) | ||
at your option. | ||
|
||
### Contribution | ||
|
||
Unless you explicitly state otherwise, any contribution intentionally submitted | ||
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any | ||
additional terms or conditions. | ||
|
||
[HashMap]: https://doc.rust-lang.org/std/collections/struct.HashMap.html |