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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::collections::hash_map::DefaultHasher;
use std::fmt::Debug;
use std::fmt::Display;
use std::hash::Hash;
use std::hash::Hasher;
pub trait Name {
fn name(&self) -> String;
}
pub trait Named = Display + Name;
pub trait KeyLike = Eq + Hash + Copy + Debug + Sized;
pub trait DataLike = KeyLike + Named + Default;
pub trait IndexLike: KeyLike + PartialOrd + Ord {
fn from_usize(value: usize) -> Self;
fn to_usize(&self) -> usize;
fn invalid() -> Self;
fn decr(&mut self) {
let value = self.to_usize();
assert!(value > 0);
*self = Self::from_usize(value - 1);
}
fn incr(&mut self) {
assert!(self.is_valid());
let value = self.to_usize();
*self = Self::from_usize(value + 1);
assert!(self.is_valid());
}
fn is_valid(&self) -> bool {
*self != Self::invalid()
}
}
pub(crate) const RIGHT_ARROW: &str = "→";
pub(crate) const RIGHT_DOUBLE_ARROW: &str = "⇒";
pub(crate) fn calculate_string_hash(string: &str) -> u64 {
let mut hasher = DefaultHasher::new();
string.hash(&mut hasher);
hasher.finish()
}
pub(crate) fn calculate_strings_hash(first: &str, second: &str) -> u64 {
let mut hasher = DefaultHasher::new();
first.hash(&mut hasher);
second.hash(&mut hasher);
hasher.finish()
}