1use std::collections::hash_map::DefaultHasher;
4use std::fmt::Debug;
5use std::fmt::Display;
6use std::hash::Hash;
7use std::hash::Hasher;
8
9pub trait Name {
11 fn name(&self) -> String;
12}
13
14pub trait Named = Display + Name;
17
18pub trait KeyLike = Eq + Hash + Copy + Debug + Sized;
20
21pub trait DataLike = KeyLike + Named + Default;
23
24pub trait IndexLike: KeyLike + PartialOrd + Ord {
26 fn from_usize(value: usize) -> Self;
28
29 fn to_usize(&self) -> usize;
31
32 fn invalid() -> Self;
34
35 fn decr(&mut self) {
37 let value = self.to_usize();
38 assert!(value > 0);
39 *self = Self::from_usize(value - 1);
40 }
41
42 fn incr(&mut self) {
44 assert!(self.is_valid());
45 let value = self.to_usize();
46 *self = Self::from_usize(value + 1);
47 assert!(self.is_valid());
48 }
49
50 fn is_valid(&self) -> bool {
52 *self != Self::invalid()
53 }
54}
55
56pub(crate) const RIGHT_ARROW: &str = "→";
57
58pub(crate) const RIGHT_DOUBLE_ARROW: &str = "⇒";
59
60pub(crate) fn calculate_string_hash(string: &str) -> u64 {
61 let mut hasher = DefaultHasher::new();
62 string.hash(&mut hasher);
63 hasher.finish()
64}
65
66pub(crate) fn calculate_strings_hash(first: &str, second: &str) -> u64 {
67 let mut hasher = DefaultHasher::new();
68 first.hash(&mut hasher);
69 second.hash(&mut hasher);
70 hasher.finish()
71}