```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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
```
``````//! ## Keylist
//! Map like wrapper around a list with tuple pairs. Inspired by Elixir's Keyword lists.
//!
//! Because it is just a list with tuples, keys can be anything that can be put in a tuple. Also means that getting a value is not efficient.
//!
//! For something more usefull and quite similar take a look at: https://docs.rs/multimap
//! ```
//! use keylist::Keylist;
//!
//! let mut keylist = Keylist::from(vec![("a", 5), ("b", 2), ("a", 1)]);
//!
//! assert_eq!(keylist.get(&"a"), Some(&5));
//!
//! keylist.sort_by_value();
//!
//! assert_eq!(keylist.get(&"a"), Some(&1));
//!
//! keylist.push("z", 26);
//!
//! assert_eq!(keylist.get(&"z"), Some(&26));
//!
//! keylist.insert(1, "z", 2);
//!
//! assert_eq!(keylist.get(&"z"), Some(&2));
//!
//! assert_eq!(keylist.get_all(&"z"), vec![&2, &26]);
//!
//! assert_eq!(keylist.get_key_value(&"b"), Some(&("b", 2)));
//!
//! let mut swapped_keylist = keylist.into_swapped();
//!
//! assert_eq!(swapped_keylist.get(&2), Some(&"z"));
//!
//! assert_eq!(swapped_keylist.get_all(&2), vec![&"z", &"b"]);
//!
//! swapped_keylist.sort();
//!
//! assert_eq!(swapped_keylist.get_all(&2), vec![&"b", &"z"]);
//!
//! swapped_keylist.extend(vec![(3, "b"), (2, "g")]);
//!
//! assert_eq!(swapped_keylist.get_all(&2), vec![&"b", &"z", &"g"]);
//!
//! ```
//!
//! Convert keylist to map and back:
//! ```
//! use std::collections::HashMap;
//! use std::iter::FromIterator;
//! use keylist::Keylist;
//!
//! let keylist = Keylist::from(vec![("a", 5), ("b", 2), ("c", 1)]);
//!
//! let mut map = HashMap::new();
//! map.extend(vec![("a", 5), ("b", 2), ("c", 1)]);
//!
//! let map_from_keylist = HashMap::from_iter(keylist.clone());
//! let mut keylist_from_map = Keylist::from_iter(map.clone());
//! keylist_from_map.sort();
//!
//! assert_eq!(map, map_from_keylist);
//! assert_eq!(keylist, keylist_from_map);
//! ```
//!
//! Arbitrary example:
//! ```
//! use keylist::Keylist;
//!
//! let mut keylist = Keylist::new();
//! keylist.push(vec![3.12, 0.12], "a");
//! keylist.push(vec![0.1235, 34.121551], "c");
//!
//! assert_eq!(keylist.get(&vec![0.1235, 34.121551]), Some(&"c"));
//!
//!
//! ```
//!
//! ## HashKeylist
//! There is also a more efficient implemetation, backend by a hashmap, therefore the keys should be hashable.
//! ```
//! use keylist::HashKeylist;
//! use std::collections::HashMap;
//! use std::iter::FromIterator;
//!
//! let mut map = HashMap::new();
//! map.insert("one", 1);
//! map.insert("two", 2);
//! map.insert("three", 3);
//! map.insert("four", 4);
//!
//! let mut keylist = HashKeylist::from_iter(map);
//! // sorts keys alphabetically
//! keylist.sort_by_key();
//!
//! keylist.push("one", 11);
//! keylist.push("five", 5);
//! keylist.push("five", 1);
//!
//! assert_eq!(
//!     vec![
//!         (&"four", &4),
//!         (&"one", &1),
//!         (&"three", &3),
//!         (&"two", &2),
//!         (&"one", &11),
//!         (&"five", &5),
//!         (&"five", &1),
//!     ],
//!     keylist.iter().collect::<Vec<_>>()
//! );
//!
//! keylist.insert(2, "five", 12);
//!
//! assert_eq!(
//!     vec![
//!         (&"four", &4),
//!         (&"one", &1),
//!         (&"five", &12),
//!         (&"three", &3),
//!         (&"two", &2),
//!         (&"one", &11),
//!         (&"five", &5),
//!         (&"five", &1),
//!     ],
//!     keylist.iter().collect::<Vec<_>>()
//! );
//!
//! assert_eq!(Some(("five", 1)), keylist.pop());
//!
//! assert_eq!(
//!     vec![
//!         (&"four", &4),
//!         (&"one", &1),
//!         (&"five", &12),
//!         (&"three", &3),
//!         (&"two", &2),
//!         (&"one", &11),
//!         (&"five", &5),
//!     ],
//!     keylist.iter().collect::<Vec<_>>()
//! );
//!
//! assert_eq!(("two", 2), keylist.remove(4));
//!
//! assert_eq!(
//!     vec![
//!         (&"four", &4),
//!         (&"one", &1),
//!         (&"five", &12),
//!         (&"three", &3),
//!         (&"one", &11),
//!         (&"five", &5),
//!     ],
//!     keylist.iter().collect::<Vec<_>>()
//! );
//!
//! assert_eq!(
//!     vec![&"four", &"one", &"five", &"three", &"one", &"five"],
//!     keylist.keys().collect::<Vec<_>>()
//! );
//!
//! assert_eq!(
//!     vec![&4, &1, &12, &3, &11, &5],
//!     keylist.values().collect::<Vec<_>>()
//! );
//!
//! assert_eq!(
//!     vec![
//!         ("four", 4),
//!         ("one", 1),
//!         ("five", 12),
//!         ("three", 3),
//!         ("one", 11),
//!         ("five", 5),
//!     ],
//!     Vec::from(keylist)
//! )
//! ```

pub mod hash_keylist;
pub mod vec_keylist;

pub use hash_keylist::HashKeylist;
pub use vec_keylist::VecKeylist;

pub type Keylist<K, V> = VecKeylist<K, V>;
``````