Skip to content

VecMap::from(Vec) and VecSet::from(Vec) keep different duplicates than from_iter / from([..]) #66

@extremeandy

Description

@extremeandy

Duplicate-key resolution differs between constructors on the same type:

use vecmap::VecMap;

let pairs = vec![("a", 1), ("a", 2), ("a", 3)];

VecMap::from(pairs.clone()).get("a");                          // Some(&1)  first wins
pairs.clone().into_iter().collect::<VecMap<_, _>>().get("a");  // Some(&3)  last wins
VecMap::from([("a", 1), ("a", 2), ("a", 3)]).get("a");         // Some(&3)  last wins

VecSet has the analogous split (visible when T's Eq ignores a field).

From<Vec<_>> uses crate::dedup (keeps first); FromIterator / From<[_; N]> go through Extendinsertmem::replace (keeps last). std's HashMap/BTreeMap uniformly keep the last; HashSet/BTreeSet uniformly keep the first.

Happy to send a PR - probably aligning From<Vec<_>> with FromIterator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions