40 Commits

Author SHA1 Message Date
Alex Martens
4799f8ce10 docs: modernize intra doc links 2023-10-31 21:06:44 -07:00
Dario Nieuwenhuis
92b72b1334 indexmap: add another previously-failing assert. 2023-10-31 02:43:53 +01:00
Shaun Bennett
a4bfe3e655 indexmap: use correct index when inserting through entry api
When inserting using the entry API and the robin-hood case is hit,
we currently return using the incorrect index, which in turn
returns a reference to the wrong entry in the map, causing
undefined behaviour in the API.
2023-10-31 02:21:45 +01:00
Jean-Pierre De Jesus DIAZ
9fe93fd6d1
export all IndexMap iterators
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
2023-01-20 13:45:17 +01:00
bors[bot]
b3ddffbe2e
Merge #335
335: Implement retain for IndexSet/IndexMap. r=korken89 a=jeandudey

Needed to remove IndexMap/IndexSet elements while iterating over it.

Co-authored-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
2023-01-11 19:45:27 +00:00
Jean-Pierre De Jesus DIAZ
837f322515
export Iter from IndexSet and IndexMap 2023-01-11 13:42:03 +01:00
Jean-Pierre De Jesus DIAZ
f7766eae67
implement retain for IndexMap/IndexSet
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
2023-01-10 14:00:39 +01:00
Jean-Pierre De Jesus DIAZ
c9cc18ada7
relax trait requirements on IndexMap
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
2023-01-10 11:59:59 +01:00
Jorge Aparicio
fdcfd4c2f1 clarify the iteration order of IndexMap / IndexSet
closes #321
2022-10-20 16:51:15 +02:00
Jorge Aparicio
4491015467 speed up cargo miri test
by making some "exhaustive" tests less exhaustive
2022-09-07 19:24:24 +02:00
Jorge Aparicio
730ab75741 [breaking-change] use hash32 v0.3.0
this release of `hash32` has the advantage that 32-bit hashers can be used to hash types that
implement the `core:#️⃣:Hash` trait removing the need for the `hash32::Hash` implementations in
this crate and the uses of the `#[derive(Hash32)]` macro (which did not support enums) in dependent
crates

with this change the following code works
``` rust
// NOTE no derive(Hash32)
struct Int(i32);

let mut x = FnvIndexSet::<_, 4>::default();
let _ = x.insert(Int(0));
```

this change is technically a breaking change because the following code is no longer accepted

``` rust
// assume this type comes from a dependency
// NOTE no derive(Hash)
struct Int(i32);

let mut x = FnvIndexSet::<_, 4>::default();
let _ = x.insert(Int(0)); // error: does not implement Hash
```
2022-08-12 15:57:01 +02:00
Ben Kimock
270db441f7 Fix OOB get_unchecked, shadow Vec::as_ptr methods
The fixes in #280 missed one instance of UB. The get_unchecked_mut
inside VacantEntry::Insert can be out of bounds of the initialized
region of the backing Vec. When that happens, the call is UB. This is
detected both by the standard library's debug assertions which can be
enabled with -Zbuild-std and with Miri but only with
-Zmiri-tag-raw-pointers.

This also adds inherent as_ptr and as_mut_ptr methods to Vec which
shadow those provided by the Deref to a slice. Without this shadowing,
the change from get_unchecked_mut to as_mut_ptr.add wouldn't actually
fix the problem identified by the debug assertions or Miri, it just
hides it from the debug assertions. The core problem is that references
narrow provenance, so if we want to access outside of the initialized
region of a Vec we need to get a pointer to the array without passing
through a reference to the initialized region first. The pointers from
these shadowing methods can be used to access anywhere in the allocation,
whereas vec.as_slice().as_ptr() would be UB to use for access into the
uninitialized region.
2022-06-18 19:37:26 -04:00
Jorge Aparicio
1379a9859c compile-time check power of two invariant in Index{Set,Map}'s default method
closes #295
2022-06-14 12:30:52 +02:00
Jorge Aparicio
7fd32f8a02 add first/last API to IndexMap and IndexSet 2022-05-12 12:54:15 +02:00
Jorge Aparicio
1735e6e58c rustfmt 2022-05-09 16:58:01 +02:00
gramar
9b03b5940d Drive-by fix insert on full map 2022-05-09 16:57:03 +02:00
gramar
d2c85a18e0 Add entry API 2022-05-09 16:55:32 +02:00
Jorge Aparicio
fa1e92dacd rustfmt 2022-05-09 16:53:10 +02:00
gramar
8b3c7f238a Add intoiter for Indexmap 2022-03-23 13:38:15 +01:00
Emil Fresk
318da23c43 Fix bounds in IndexMap and IndexSet, IndexSet::new() is now const 2021-12-16 10:37:23 +01:00
Emil Fresk
58cb279aec IndexMap::new() is now a const-fn 2021-04-19 21:36:38 +02:00
Emil Fresk
73d209a0ef
Merge branch 'master' into const_generics 2021-04-01 19:16:21 +02:00
Emil Fresk
1444990e52 Cleanup and HistoryBuffer is now const and using MaybeUninit 2021-04-01 19:14:40 +02:00
Roman Proskuryakov
7fb276f6dc Fix warnings in src/indexmap.rs 2021-03-28 11:04:39 +03:00
Roman Proskuryakov
f7cb3e575f Fix fmt 2021-03-28 09:48:34 +03:00
Syrus Akbary
de20c36cf2
Fix typo 2021-03-26 11:19:17 +01:00
Emil Fresk
3de878b09e Cleanup 2021-03-25 19:42:21 +01:00
Emil Fresk
8ba71d4b14 Merge branch 'master' into const_generics 2021-03-25 17:45:10 +01:00
Per Lindgren
f962e3a45f Initial conversion to const generics
vec passes tests

vec passes tests with docs as well (besides one with FromIter)

vec passes tests with docs as well (besides one with FromIter)

exposing full API

passing all current tests

starting with string

string test passes mostly

string test passes

ufmt passes

TODO removed

binary_heap wip

binary_heap passes tests

sealed passes

spsc wip

spsc wip2

split wip3

spcs and split passes --lib tests

spcs and split passes --lib tests

spcs and split passes --lib tests

spcs and split passes all tests (doc + lib)

indexmap wip

indexmap passes --lib test

indexmap passes all tests (lib + doc)

indexset passes all tests (lib + doc)

indexset passes all tests (lib + doc)

linear map wip

linear map all test (lib + doc) passes, drop not tested, into_iter(mut self) not implemented

history buffer all test pass (doc + lib), Copy instead of clone atm

serde does not work

pool works, serde still not

serde wip

serde wip

serde wip

serde wip
2021-03-25 16:31:58 +01:00
Lotte Steenbrink
61b85596cf IndexMap, IndexSet: hint to FnvIndex... in the docs, copy examples to Fnv... docs, add direct links 2020-12-16 10:23:01 +01:00
Jorge Aparicio
cb8179a30e run cargo fmt 2019-12-18 12:41:17 +01:00
Jorge Aparicio
4932eb27df use core::mem::MaybeUninit; drop min-const-fn and smaller-atomics features 2019-05-03 14:00:28 +02:00
Felix Stegmaier
37f773493f Add test for Eq of IndexMap 2019-02-11 22:09:21 +01:00
Felix Stegmaier
7107014806 Implement PartialEq and Eq for IndexMap 2019-02-11 22:06:53 +01:00
Artem Vorotnikov
4b09a24573
impl Clone for all containers 2019-02-05 18:19:41 +03:00
Jorge Aparicio
9c89b3ea49 cargo fmt 2018-10-19 19:34:00 +02:00
Jorge Aparicio
ffc7849f27 avoid using NLL 2018-05-03 03:35:46 +02:00
Jorge Aparicio
e8ef25eee1 add more functionality to Vec 2018-04-23 20:24:53 +02:00
Jorge Aparicio
f60ae0d3e0 add example to IndexMap.remove 2018-04-23 19:43:57 +02:00
Jorge Aparicio
f58f7abfed port IndexMap and IndexSet 2018-04-23 19:40:36 +02:00