File: btree_set_hash.rs

package info (click to toggle)
rustc 1.70.0%2Bdfsg1-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 722,120 kB
  • sloc: xml: 147,962; javascript: 10,210; sh: 8,590; python: 8,220; ansic: 5,901; cpp: 4,635; makefile: 4,001; asm: 2,856
file content (29 lines) | stat: -rw-r--r-- 668 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::hash;
use std::collections::BTreeSet;

#[test]
fn test_hash() {
    let mut x = BTreeSet::new();
    let mut y = BTreeSet::new();

    x.insert(1);
    x.insert(2);
    x.insert(3);

    y.insert(3);
    y.insert(2);
    y.insert(1);

    assert_eq!(hash(&x), hash(&y));
}

#[test]
fn test_prefix_free() {
    let x = BTreeSet::from([1, 2, 3]);
    let y = BTreeSet::<i32>::new();

    // If hashed by iteration alone, `(x, y)` and `(y, x)` would visit the same
    // order of elements, resulting in the same hash. But now that we also hash
    // the length, they get distinct sequences of hashed data.
    assert_ne!(hash(&(&x, &y)), hash(&(&y, &x)));
}