1use crate::{CapeStringHashKey,C,CapeStringImpl,CapeStringConstProvider};
2
3pub struct CapeOpenMap<V> (std::collections::HashMap<CapeStringHashKey<'static>,V,fxhash::FxBuildHasher>);
60
61impl<V> CapeOpenMap<V> {
62
63 pub fn new() -> Self {
64 Self(std::collections::HashMap::with_hasher(fxhash::FxBuildHasher::default()))
65 }
66
67 pub fn with_capacity(capacity: usize) -> Self {
68 Self(std::collections::HashMap::with_capacity_and_hasher(capacity,fxhash::FxBuildHasher::default()))
69 }
70
71 pub fn capacity(&self) -> usize {
72 self.0.capacity()
73 }
74
75 pub fn keys(&self) -> std::collections::hash_map::Keys<'_, CapeStringHashKey<'static>, V> {
76 self.0.keys()
77 }
78
79 pub fn into_keys(self) -> std::collections::hash_map::IntoKeys<CapeStringHashKey<'static>, V> {
80 self.0.into_keys()
81 }
82
83 pub fn values(&self) -> std::collections::hash_map::Values<'_, CapeStringHashKey<'static>, V> {
84 self.0.values()
85 }
86
87 pub fn values_mut(&mut self) -> std::collections::hash_map::ValuesMut<'_, CapeStringHashKey<'static>, V> {
88 self.0.values_mut()
89 }
90
91 pub fn into_values(self) -> std::collections::hash_map::IntoValues<CapeStringHashKey<'static>, V> {
92 self.0.into_values()
93 }
94
95 pub fn iter(&self) -> std::collections::hash_map::Iter<'_, CapeStringHashKey<'static>, V> {
96 self.0.iter()
97 }
98
99 pub fn iter_mut(&mut self) -> std::collections::hash_map::IterMut<'_, CapeStringHashKey<'static>, V> {
100 self.0.iter_mut()
101 }
102
103 pub fn len(&self) -> usize {
104 self.0.len()
105 }
106
107 pub fn is_empty(&self) -> bool {
108 self.0.is_empty()
109 }
110
111 pub fn drain(&mut self) -> std::collections::hash_map::Drain<'_, CapeStringHashKey<'static>, V> {
112 self.0.drain()
113 }
114
115 pub fn retain<F>(&mut self, f: F)
116 where F: FnMut(&CapeStringHashKey<'static>, &mut V) -> bool {
117 self.0.retain(f)
118 }
119
120 pub fn clear(&mut self) {
121 self.0.clear()
122 }
123
124 pub fn reserve(&mut self, additional: usize) {
125 self.0.reserve(additional)
126 }
127
128 pub fn try_reserve(&mut self, additional: usize) -> Result<(), std::collections::TryReserveError> {
129 self.0.try_reserve(additional)
130 }
131
132 pub fn shrink_to_fit(&mut self) {
133 self.0.shrink_to_fit()
134 }
135
136 pub fn shrink_to(&mut self, min_capacity: usize) {
137 self.0.shrink_to(min_capacity)
138 }
139
140 pub fn entry(&mut self, key: CapeStringHashKey<'static>) -> std::collections::hash_map::Entry<'_, CapeStringHashKey<'static>, V> {
141 self.0.entry(key)
142 }
143
144 pub fn get<'a,'b,Q:CapeStringConstProvider>(&'a self, k: &'b Q) -> Option<&'a V> where 'b:'a {
145 let k = CapeStringHashKey::from_string_constant(k);
146 self.0.get(&k)
147 }
148
149 pub fn get_mut<'a>(&'a mut self, k: CapeStringHashKey<'static>) -> Option<&'a mut V> {
150 self.0.get_mut(&k)
151 }
152
153 pub fn contains_key<Q:CapeStringConstProvider>(&self, k: &Q) -> bool {
154 let k = CapeStringHashKey::from_string_constant(k);
155 self.0.contains_key(&k)
156 }
157
158 pub fn insert_from_cape_string_constant<T:CapeStringConstProvider>(&mut self, k: T, v: V) -> Option<V> {
159 let (ptr,size)=k.as_capechar_const_with_length();
160 self.0.insert(CapeStringHashKey::from_cape_char_const(ptr,size),v)
161 }
162
163 pub fn insert(&mut self, k: CapeStringHashKey<'static>, v: V) -> Option<V> {
164 self.0.insert(k,v)
165 }
166
167 pub fn remove<'a>(&'a mut self, k: CapeStringHashKey<'static>) -> Option<V> {
168 self.0.remove(&k)
169 }
170
171 pub fn remove_entry<'a>(&mut self, k: CapeStringHashKey<'static>) -> Option<(CapeStringHashKey<'static>, V)> {
172 self.0.remove_entry(&k)
173 }
174
175}
176
177impl<V:Clone> Clone for CapeOpenMap<V> {
178 fn clone(&self) -> Self {
179 Self(self.0.clone())
180 }
181}
182
183impl<V:std::fmt::Debug> std::fmt::Debug for CapeOpenMap<V> {
184 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
185 self.0.fmt(f)
186 }
187}
188
189impl <V> std::default::Default for CapeOpenMap<V> {
190 fn default() -> Self {
191 Self::new()
192 }
193}
194
195impl <V:std::cmp::PartialEq> std::cmp::PartialEq for CapeOpenMap<V> {
196 fn eq(&self, other: &Self) -> bool {
197 self.0.eq(&other.0)
198 }
199}
200
201impl <V:std::cmp::Eq> std::cmp::Eq for CapeOpenMap<V> {}
202