File: 116519.rs

package info (click to toggle)
rustc 1.86.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 913,560 kB
  • sloc: xml: 158,127; python: 35,921; javascript: 19,689; sh: 19,600; cpp: 18,906; ansic: 13,124; asm: 4,376; makefile: 708; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (57 lines) | stat: -rw-r--r-- 1,424 bytes parent folder | download | duplicates (15)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//@ known-bug: #116519
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
trait Ret {
    type R;
}
struct Cond<const PRED: bool, U, V>(std::marker::PhantomData<U>, std::marker::PhantomData<V>);
impl<U, V> Ret for Cond<true, U, V> {
    type R = U;
}
impl<U, V> Ret for Cond<false, U, V> {
    type R = V;
}
struct RobinHashTable<
    const MAX_LENGTH: usize,
    CellIdx = <Cond<{ MAX_LENGTH < 65535 }, u16, u32> as Ret>::R,
> {
    _idx: CellIdx,
}
impl<CellIdx> RobinHashTable<MAX_LENGTH, CellIdx> {
    fn new() -> Self {
        Self {
            _idx: CellIdx { MAX_LENGTH },
        }
    }
}
impl<CellIdx> HashMapBase<CellIdx> {
    fn new() -> Self {
        Self {
            _idx: CellIdx { 0 },
        }
    }
}
impl<CellIdx> HashMapBase<CellIdx> for RobinHashTable<MAX_LENGTH, CellIdx> {
    fn hash<H: Hash + Hasher>(&self,

    ) -> H {
        self._idx.hash()
    }
    fn eq(&self, other: &Self) -> bool {
        self._idx.eq(other._idx)
    }
}
impl<CellIdx> HashMapBase<CellIdx> for RobinHashTable<MAX_LENGTH, CellIdx> {
    fn hash<H: Hash + Hasher>(&self, other: &Self) -> H {
        self._idx.hash(other._idx)
    }
    fn eq(&self, other: &Self) -> bool {
        self._idx.eq(other._idx)
    }
}
#[test]
fn test_size_of_robin_hash_table() {
    use std::mem::size_of;
    println!("{}", size_of::<RobinHashTable<1024>>());
    println!("{}", size_of::<RobinHashTable<65536>>());
}