Commit Graph

299 Commits

Author SHA1 Message Date
Taiki Endo af933ddcdf Fix outdated docs 2020-12-01 11:44:28 +09:00
Josh Stone 8623baaf57 Reduce unsafe code with hashbrown 0.9.1 2020-09-28 18:01:57 -07:00
Josh Stone 4ed9b8717c Let feature "serde" work as well as "serde-1"
The optional dependency on `serde` creates an implicit feature, but
we've only been enabling that implementation with `"serde-1"`. Now you
can directly enable `"serde"` to get full use, and `"serde-1"` is just
kept for compatibility.

If we ever need a `"serde-2"`, that can depend on package renaming.
2020-09-16 12:46:39 -07:00
Josh Stone a7c8883040 Add documentation and examples for Index and IndexMut 2020-08-07 14:45:09 -07:00
Josh Stone b830148a9d Implement direct usize indexing
```rust
where
    IndexMap<K, V, S>: IndexMut<usize, Output = V>,
    IndexSet<T, S>: Index<usize, Output = T>,
```

This allows `map[i]` and `set[i]` indexing to access values directly,
panicking if the index is out of bounds, similar to slices.

On maps, this somewhat overlaps with `Index<&Q> + IndexMut<&Q>` where
`Q: Equivalent<K>`. The reference makes this indexing unambiguous, but
it could be confusing to users if the key type is also an integer.
2020-08-07 14:45:07 -07:00
Josh Stone aa3511aaca Merge pull request #142 from cuviper/drain-ranges
Expand drain to accept any RangeBounds<usize>
2020-08-07 14:39:11 -07:00
Josh Stone f935d6ff72 Relax IntoParallelIterator for &'a mut IndexMap 2020-07-24 14:39:23 -07:00
Josh Stone 816ebebf37 Expand drain to accept any RangeBounds<usize>
Rather than just `RangeFull`, this lets us accept any `Range*` type or
even arbitrary `Bound` pairs, matching the signature of `Vec::drain`.
2020-07-24 12:53:26 -07:00
Josh Stone 7ad118fd62 Relax some bounds to match std 2020-07-23 16:42:23 -07:00
Josh Stone 532eec1dfc style: use more anonymous lifetimes 2020-07-23 14:17:49 -07:00
Josh Stone 71128ab32b Stop using local_inner_macros 2020-07-20 13:19:18 -07:00
Josh Stone 4433ac97ca cargo fix --edition-idioms 2020-07-20 13:14:08 -07:00
Josh Stone b95c8949e7 edition = "2018" 2020-07-20 13:03:05 -07:00
Josh Stone 1fd40f58a5 cargo fix --edition 2020-07-20 12:59:24 -07:00
Josh Stone 8d8f074341 Always use #![nostd] and make std:: explicit
The fake `std` module we had in our root will make things difficult when
we switch to 2018, where there's a path difference between `std::` for
the crate and `crate::std::` for our module.
2020-07-20 12:57:50 -07:00
Josh Stone bf63d2c517 Use new methods in hashbrown 0.8.1 2020-07-16 14:56:52 -07:00
Josh Stone af4e5e47ed Use plain clear instead of clear_no_drop
It was an over-optimization to use `clear_no_drop`, which hurts the
possibility of using griddle as an alternate table implementation.
2020-07-16 14:16:20 -07:00
Josh Stone 00fba2104d Encapsulate unsafe code in a raw module 2020-07-16 14:16:20 -07:00
bluss 9bc1c9e971 Make methods that get RawBucket parameters unsafe; add safety comments
These methods trust their caller to pass correct RawBucket values, so we
mark them unsafe to use the common safe/unsafe distinction. I used
allow(unused_unsafe) to write the functions in the (hopefully) future
style of internal unsafe blocks in unsafe functions.
2020-07-16 14:16:20 -07:00
Josh Stone 871f30d15d Don't shadow raw_bucket variables 2020-07-16 14:16:20 -07:00
Josh Stone 43aff095cf Document the return value of IndexMapCore::push 2020-07-16 14:16:20 -07:00
Josh Stone dd5bf1c847 Only rebuild if retain actually changed something 2020-07-16 14:16:20 -07:00
Josh Stone f315c7724d Move cmp into the sorting closures 2020-07-16 14:16:20 -07:00
Josh Stone 3b66d46460 Add a top-level comment about allowed unsafe 2020-07-16 14:16:20 -07:00
Josh Stone be4853c948 Raise the MSRV to 1.32 for hashbrown 2020-07-16 14:16:20 -07:00
Josh Stone 5e11c442f6 Switch to hashbrown's RawTable internally 2020-07-16 14:16:20 -07:00
Josh Stone 1e5da1be98 Add more methods matching the standard HashMap
- `pub fn get_key_value<Q: ?Sized>(&self, key: &Q) -> Option<(&K, &V)>`
  - Stabilized in Rust 1.40.
  - This is a middle-ground between `get` and our own `get_full` that
    includes the index. It's easy enough to add for compatibility.

- `pub fn remove_entry<Q: ?Sized>(&mut self, key: &Q) -> Option<(K, V)>`
  - Stabilized in Rust 1.27.
  - For `IndexMap`, this also adds `swap_`/`shift_remove_entry` choices.
  - These are also a middle-ground between (`swap_`/`shift_`)`remove` and
    our own `swap`/`shift_remove_full` that include the index. We don't
    have a plain `remove_full` though.
2020-07-08 16:00:42 -07:00
Josh Stone 84bdaa8b80 Demonstrate fnv and fxhash as alternate hashers 2020-06-25 11:09:33 -07:00
Josh Stone d72991a29e Avoid index fixups in sorted_by 2020-06-09 12:31:16 -07:00
Josh Stone ae47ee43df Simplify calls to find_existing_entry 2020-06-09 12:31:16 -07:00
Josh Stone cf477e3f1a Implement clone_from to reuse allocations 2020-06-09 12:31:16 -07:00
Josh Stone 4cb690cda3 derive(Clone, PartialEq) for HashValue 2020-06-09 12:31:16 -07:00
Josh Stone aad733f8e3 cargo fmt 2020-06-09 12:31:16 -07:00
Josh Stone 0ab1ab0711 Make IndexMapCore fields private 2020-06-09 12:31:13 -07:00
Josh Stone 9f9960e568 Move entry fully into the core 2020-06-09 12:30:20 -07:00
Josh Stone 0f209e1edb Move retain fully into the core 2020-06-09 12:30:20 -07:00
Josh Stone 1bddfb91e6 Move insert fully into the core 2020-06-09 12:30:20 -07:00
Josh Stone 04ef50a167 Split IndexMapCore to its own module 2020-06-09 12:30:17 -07:00
Josh Stone 9292b3e31c Rename vestigial OrderMap references to IndexMap
These are all internal, not affecting public API.
2020-06-09 12:26:44 -07:00
Josh Stone 08377e4676 Merge pull request #126 from mwillsey/master
Unify the entry and insert code
2020-06-09 12:26:13 -07:00
Josh Stone ae7a599112 nit: add newlines between MakeEntry methods 2020-06-09 12:07:04 -07:00
Mark LeMoine b2eb7c64c1 Fix off-by-one error in reindexing after reverse 2020-06-08 15:28:39 -07:00
Mark LeMoine 817559cb5e Make reverse actually use O(1) space 2020-06-08 15:16:49 -07:00
Mark LeMoine 578a853f8f Add reverse to OrderMapCore, IndexMap, IndexSet 2020-06-08 02:12:57 -07:00
Max Willsey 9248332563 Fix typo
Co-authored-by: Josh Stone <cuviper@gmail.com>
2020-06-06 11:00:10 -07:00
Max Willsey 7e49f6e737 Neaten up some things 2020-06-05 12:15:05 -07:00
Max Willsey 55bfc34819 Unify the entry and insert code 2020-06-05 10:21:51 -07:00
Josh Stone bc4ee74102 Merge pull request #120 from bluss/get-index-of
Rename entry_index to get_index_of
2020-04-14 16:59:33 -07:00
bluss 89aac5a88c MAINT: Update rust version for dev/CI to 1.32
Newer rand versions require newer Rust, and we only need it for testing,
so it's no big deal.
2020-04-11 12:32:32 +02:00
bluss 4d454bc5da FIX: Rename entry_index to get_index_of 2020-04-11 10:07:01 +02:00