@@ -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,10 @@ 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 )
849
+ SHARING_MAPT ( void )::erase(const key_type &k)
875
850
{
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
-
883
851
innert *del = nullptr ;
884
852
std::size_t del_bit = 0 ;
885
- std::size_t del_level = 0 ;
886
853
887
854
std::size_t key = hash ()(k);
888
855
innert *ip = ↦
@@ -897,52 +864,29 @@ SHARING_MAPT2(, size_type)::erase(const key_type &k, const tvt &key_exists)
897
864
{
898
865
del = ip;
899
866
del_bit=bit;
900
- del_level = i;
901
867
}
902
868
903
869
ip = ip->add_child (bit);
904
870
905
871
key >>= chunk;
906
872
}
907
873
874
+ PRECONDITION (!ip->empty ());
908
875
const leaf_listt &ll = as_const (ip)->get_container ();
876
+ PRECONDITION (!ll.empty ());
909
877
910
878
// forward list has one element
911
- if (!ll. empty () && std::next (ll.begin ()) == ll.end ())
879
+ if (std::next (ll.begin ()) == ll.end ())
912
880
{
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 ;
881
+ PRECONDITION (equalT ()(ll.front ().get_key (), k));
882
+ del->remove_child (del_bit);
925
883
}
926
-
927
- SM_ASSERT (!ll.empty ());
928
-
929
- ip->remove_leaf (k);
930
- 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)
884
+ else
941
885
{
942
- cnt+= erase (k, key_exists );
886
+ ip-> remove_leaf (k );
943
887
}
944
888
945
- return cnt ;
889
+ num-- ;
946
890
}
947
891
948
892
SHARING_MAPT4 (valueU, void )
0 commit comments