@@ -157,14 +157,6 @@ Author: Daniel Poetzl
157
157
// / For this to work, the type of the values stored in the map needs to have a
158
158
// / defined equality operator (operator==).
159
159
// /
160
- // / Several methods take a hint indicating whether the element is known not to
161
- // / be in the map (`false`), known to be in the map (`true`), or it is unknown
162
- // / whether the element is in the map (`unknown`). The value `unknown` is always
163
- // / valid. When `true` or `false` are given they need to be accurate, otherwise
164
- // / the behavior is undefined. A correct hint can prevent the need to follow a
165
- // / path from the root to a key-value pair twice (e.g., once for checking that
166
- // / it exists, and second for copying nodes).
167
- // /
168
160
// / In the descriptions of the methods of the sharing map we also give the
169
161
// / complexity of the operations. We use the following symbols:
170
162
// / - N: number of key-value pairs in the map
@@ -221,31 +213,14 @@ class sharing_mapt
221
213
public:
222
214
// interface
223
215
224
- // / Erase element
216
+ // / Erase element, element must exist in map
225
217
// /
226
218
// / Complexity:
227
219
// / - Worst case: O(H * S + M)
228
220
// / - Best case: O(H)
229
221
// /
230
222
// / \param k: The key of the element to erase
231
- // / \param key_exists: Hint to indicate whether the element is known to exist
232
- // / (possible values `unknown` or` true`)
233
- size_type erase (const key_type &k, const tvt &key_exists = tvt::unknown());
234
-
235
- // / Erase all elements
236
- // /
237
- // / Complexity:
238
- // / - Worst case: O(K * (H * S + M))
239
- // / - Best case: O(K * H)
240
- // /
241
- // / \param ks: The keys of the element to erase
242
- // / \param key_exists: Hint to indicate whether the elements are known to
243
- // / exist (possible values `unknown` or `true`). Applies to all elements
244
- // / (i.e., have to use `unknown` if for at least one element it is not known
245
- // / whether it exists)
246
- size_type erase_all (
247
- const keyst &ks,
248
- const tvt &key_exists = tvt::unknown()); // applies to all keys
223
+ void erase (const key_type &k);
249
224
250
225
// / Insert element, element must not exist in map
251
226
// /
@@ -871,18 +846,9 @@ SHARING_MAPT2(const, innert *)::get_container_node(const key_type &k) const
871
846
return ip;
872
847
}
873
848
874
- SHARING_MAPT2 (, size_type)::erase(const key_type &k, const tvt &key_exists)
875
- {
876
- SM_ASSERT (!key_exists.is_false ());
877
- SM_ASSERT (!key_exists.is_true () || has_key (k));
878
-
879
- // check if key exists
880
- if (key_exists.is_unknown () && !has_key (k))
881
- return 0 ;
882
-
849
+ SHARING_MAPT (void )::erase(const key_type &k) {
883
850
innert *del = nullptr ;
884
851
std::size_t del_bit = 0 ;
885
- std::size_t del_level = 0 ;
886
852
887
853
std::size_t key = hash ()(k);
888
854
innert *ip = ↦
@@ -897,52 +863,26 @@ SHARING_MAPT2(, size_type)::erase(const key_type &k, const tvt &key_exists)
897
863
{
898
864
del = ip;
899
865
del_bit=bit;
900
- del_level = i;
901
866
}
902
867
903
868
ip = ip->add_child (bit);
904
869
905
870
key >>= chunk;
906
871
}
907
872
873
+ PRECONDITION (!ip->empty ());
908
874
const leaf_listt &ll = as_const (ip)->get_container ();
875
+ PRECONDITION (!ll.empty ());
909
876
910
877
// forward list has one element
911
- if (!ll.empty () && std::next (ll.begin ()) == ll.end ())
912
- {
913
- if (del_level < steps - 1 )
914
- {
915
- del->remove_child (del_bit);
916
- }
917
- else
918
- {
919
- SM_ASSERT (del_level == steps - 1 );
920
- del->remove_child (del_bit);
921
- }
922
-
923
- num--;
924
- return 1 ;
878
+ if (std::next (ll.begin ()) == ll.end ()) {
879
+ PRECONDITION (equalT ()(ll.front ().get_key (), k));
880
+ del->remove_child (del_bit);
881
+ } else {
882
+ ip->remove_leaf (k);
925
883
}
926
884
927
- SM_ASSERT (!ll.empty ());
928
-
929
- ip->remove_leaf (k);
930
885
num--;
931
-
932
- return 1 ;
933
- }
934
-
935
- SHARING_MAPT2 (, size_type)
936
- ::erase_all(const keyst &ks, const tvt &key_exists)
937
- {
938
- size_type cnt = 0 ;
939
-
940
- for (const key_type &k : ks)
941
- {
942
- cnt+=erase (k, key_exists);
943
- }
944
-
945
- return cnt;
946
886
}
947
887
948
888
SHARING_MAPT4 (valueU, void )
0 commit comments