@@ -221,18 +221,61 @@ class sharing_mapt
221
221
public:
222
222
// interface
223
223
224
+ // / Erase element
225
+ // /
226
+ // / Complexity:
227
+ // / - Worst case: O(H * S + M)
228
+ // / - Best case: O(H)
229
+ // /
230
+ // / \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`)
224
233
size_type erase (const key_type &k, const tvt &key_exists = tvt::unknown());
225
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)
226
246
size_type erase_all (
227
247
const keyst &ks,
228
248
const tvt &key_exists = tvt::unknown()); // applies to all keys
229
249
250
+ // / Insert element, element must not exist in map
251
+ // /
252
+ // / Complexity:
253
+ // / - Worst case: O(H * S + M)
254
+ // / - Best case: O(H)
255
+ // /
256
+ // / \param k: The key of the element to insert
257
+ // / \param m: The mapped value to insert
230
258
template <class valueU >
231
259
void insert (const key_type &k, valueU &&m);
232
260
261
+ // / Replace element, element must exist in map
262
+ // /
263
+ // / Complexity:
264
+ // / - Worst case: O(H * S + M)
265
+ // / - Best case: O(H)
266
+ // /
267
+ // / \param k: The key of the element to insert
268
+ // / \param m: The mapped value to replace the old value with
233
269
template <class valueU >
234
270
void replace (const key_type &k, valueU &&m);
235
-
271
+ // / Find element
272
+ // /
273
+ // / Complexity:
274
+ // / - Worst case: O(H * log(S) + M)
275
+ // / - Best case: O(H)
276
+ // /
277
+ // / \param k: The key of the element to search
278
+ // / \return optionalt containing a const reference to the value if found
236
279
optionalt<std::reference_wrapper<const mapped_type>>
237
280
find (const key_type &k) const ;
238
281
@@ -315,8 +358,51 @@ class sharing_mapt
315
358
// / that are not shared between them (also see get_delta_view()).
316
359
typedef std::vector<delta_view_itemt> delta_viewt;
317
360
361
+ // / Get a view of the elements in the map
362
+ // / A view is a list of pairs with the components being const references to
363
+ // / the keys and values in the map.
364
+ // /
365
+ // / Complexity:
366
+ // / - Worst case: O(N * H * log(S))
367
+ // / - Best case: O(N + H)
368
+ // /
369
+ // / \param [out] view: Empty view
318
370
void get_view (viewt &view) const ;
319
371
372
+ // / Get a delta view of the elements in the map
373
+ // /
374
+ // / Informally, a delta view of two maps is a view of the key-value pairs in
375
+ // / the maps that are contained in subtrees that are not shared between them.
376
+ // /
377
+ // / A delta view is represented as a list of structs, with each struct having
378
+ // / four members (`in_both`, `key`, `value1`, `value2`). The elements `key`,
379
+ // / `value1`, and `value2` are const references to the corresponding elements
380
+ // / in the map. The first element indicates whether the key exists in both
381
+ // / maps, the second element is the key, the third element is the mapped value
382
+ // / of the first map, and the fourth element is the mapped value of the second
383
+ // / map, or a dummy element if the key exists only in the first map (in which
384
+ // / case `in_both` is false).
385
+ // /
386
+ // / Calling `A.delta_view(B, ...)` yields a view such that for each element in
387
+ // / the view one of two things holds:
388
+ // / - the key is contained in both A and B, and in the maps the corresponding
389
+ // / key-value pairs are not contained in a subtree that is shared between
390
+ // / them
391
+ // / - the key is only contained in A
392
+ // /
393
+ // / When `only_common=true`, the first case above holds for every element in
394
+ // / the view.
395
+ // /
396
+ // / Complexity:
397
+ // / - Worst case: O(max(N1, N2) * H * log(S) * M1 * M2) (no sharing)
398
+ // / - Best case: O(1) (maximum sharing)
399
+ // /
400
+ // / The symbols N1, M1 refer to map A, and symbols N2, M2 refer to map B.
401
+ // /
402
+ // / \param other: other map
403
+ // / \param [out] delta_view: Empty delta view
404
+ // / \param only_common: Indicates if the returned delta view should only
405
+ // / contain key-value pairs for keys that exist in both maps
320
406
void get_delta_view (
321
407
const sharing_mapt &other,
322
408
delta_viewt &delta_view,
@@ -342,13 +428,32 @@ class sharing_mapt
342
428
std::size_t num_unique_leafs = 0 ;
343
429
};
344
430
431
+ // / Get sharing stats
432
+ // /
433
+ // / Complexity:
434
+ // / - Worst case: O(N * H * log(S))
435
+ // / - Best case: O(N + H)
436
+ // /
437
+ // / \param begin: begin iterator
438
+ // / \param end: end iterator
439
+ // / \param f: function applied to the iterator to get a sharing map
440
+ // / \return sharing stats
345
441
template <class Iterator >
346
442
static sharing_map_statst get_sharing_stats (
347
443
Iterator begin,
348
444
Iterator end,
349
445
std::function<sharing_mapt &(const Iterator)> f =
350
446
[](const Iterator it) -> sharing_mapt & { return *it; });
351
447
448
+ // / Get sharing stats
449
+ // /
450
+ // / Complexity:
451
+ // / - Worst case: O(N * H * log(S))
452
+ // / - Best case: O(N + H)
453
+ // /
454
+ // / \param begin: begin iterator of a map
455
+ // / \param end: end iterator of a map
456
+ // / \return sharing stats
352
457
template <class Iterator >
353
458
static sharing_map_statst get_sharing_stats_map (Iterator begin, Iterator end);
354
459
#endif
@@ -549,16 +654,6 @@ ::count_unmarked_nodes(
549
654
}
550
655
551
656
#if !defined(_MSC_VER)
552
- // / Get sharing stats
553
- // /
554
- // / Complexity:
555
- // / - Worst case: O(N * H * log(S))
556
- // / - Best case: O(N + H)
557
- // /
558
- // / \param begin: begin iterator
559
- // / \param end: end iterator
560
- // / \param f: function applied to the iterator to get a sharing map
561
- // / \return sharing stats
562
657
SHARING_MAPT3 (Iterator, , sharing_map_statst)
563
658
::get_sharing_stats(
564
659
Iterator begin,
@@ -604,15 +699,6 @@ ::get_sharing_stats(
604
699
return sms;
605
700
}
606
701
607
- // / Get sharing stats
608
- // /
609
- // / Complexity:
610
- // / - Worst case: O(N * H * log(S))
611
- // / - Best case: O(N + H)
612
- // /
613
- // / \param begin: begin iterator of a map
614
- // / \param end: end iterator of a map
615
- // / \return sharing stats
616
702
SHARING_MAPT3 (Iterator, , sharing_map_statst)
617
703
::get_sharing_stats_map(Iterator begin, Iterator end)
618
704
{
@@ -621,15 +707,6 @@ ::get_sharing_stats_map(Iterator begin, Iterator end)
621
707
}
622
708
#endif
623
709
624
- // / Get a view of the elements in the map
625
- // / A view is a list of pairs with the components being const references to the
626
- // / keys and values in the map.
627
- // /
628
- // / Complexity:
629
- // / - Worst case: O(N * H * log(S))
630
- // / - Best case: O(N + H)
631
- // /
632
- // / \param [out] view: Empty view
633
710
SHARING_MAPT (void )::get_view(viewt &view) const
634
711
{
635
712
SM_ASSERT (view.empty ());
@@ -654,39 +731,6 @@ ::gather_all(const baset &n, unsigned depth, delta_viewt &delta_view) const
654
731
iterate(n, depth, f);
655
732
}
656
733
657
- // / Get a delta view of the elements in the map
658
- // /
659
- // / Informally, a delta view of two maps is a view of the key-value pairs in the
660
- // / maps that are contained in subtrees that are not shared between them.
661
- // /
662
- // / A delta view is represented as a list of structs, with each struct having
663
- // / four members (`in_both`, `key`, `value1`, `value2`). The elements `key`,
664
- // / `value1`, and `value2` are const references to the corresponding elements in
665
- // / the map. The first element indicates whether the key exists in both maps,
666
- // / the second element is the key, the third element is the mapped value of the
667
- // / first map, and the fourth element is the mapped value of the second map, or
668
- // / a dummy element if the key exists only in the first map (in which case
669
- // / `in_both` is false).
670
- // /
671
- // / Calling `A.delta_view(B, ...)` yields a view such that for each element in
672
- // / the view one of two things holds:
673
- // / - the key is contained in both A and B, and in the maps the corresponding
674
- // / key-value pairs are not contained in a subtree that is shared between them
675
- // / - the key is only contained in A
676
- // /
677
- // / When `only_common=true`, the first case above holds for every element in the
678
- // / view.
679
- // /
680
- // / Complexity:
681
- // / - Worst case: O(max(N1, N2) * H * log(S) * M1 * M2) (no sharing)
682
- // / - Best case: O(1) (maximum sharing)
683
- // /
684
- // / The symbols N1, M1 refer to map A, and symbols N2, M2 refer to map B.
685
- // /
686
- // / \param other: other map
687
- // / \param [out] delta_view: Empty delta view
688
- // / \param only_common: Indicates if the returned delta view should only
689
- // / contain key-value pairs for keys that exist in both maps
690
734
SHARING_MAPT (void )
691
735
::get_delta_view(
692
736
const sharing_mapt &other,
@@ -827,15 +871,6 @@ SHARING_MAPT2(const, innert *)::get_container_node(const key_type &k) const
827
871
return ip;
828
872
}
829
873
830
- // / Erase element
831
- // /
832
- // / Complexity:
833
- // / - Worst case: O(H * S + M)
834
- // / - Best case: O(H)
835
- // /
836
- // / \param k: The key of the element to erase
837
- // / \param key_exists: Hint to indicate whether the element is known to exist
838
- // / (possible values `unknown` or` true`)
839
874
SHARING_MAPT2 (, size_type)::erase(const key_type &k, const tvt &key_exists)
840
875
{
841
876
SM_ASSERT (!key_exists.is_false ());
@@ -897,17 +932,6 @@ SHARING_MAPT2(, size_type)::erase(const key_type &k, const tvt &key_exists)
897
932
return 1 ;
898
933
}
899
934
900
- // / Erase all elements
901
- // /
902
- // / Complexity:
903
- // / - Worst case: O(K * (H * S + M))
904
- // / - Best case: O(K * H)
905
- // /
906
- // / \param ks: The keys of the element to erase
907
- // / \param key_exists: Hint to indicate whether the elements are known to exist
908
- // / (possible values `unknown` or `true`). Applies to all elements (i.e., have
909
- // / to use `unknown` if for at least one element it is not known whether it
910
- // / exists)
911
935
SHARING_MAPT2 (, size_type)
912
936
::erase_all(const keyst &ks, const tvt &key_exists)
913
937
{
@@ -921,14 +945,6 @@ ::erase_all(const keyst &ks, const tvt &key_exists)
921
945
return cnt;
922
946
}
923
947
924
- // / Insert element, element must not exist in map
925
- // /
926
- // / Complexity:
927
- // / - Worst case: O(H * S + M)
928
- // / - Best case: O(H)
929
- // /
930
- // / \param k: The key of the element to insert
931
- // / \param m: The mapped value to insert
932
948
SHARING_MAPT4 (valueU, void )
933
949
::insert(const key_type &k, valueU &&m)
934
950
{
@@ -939,14 +955,6 @@ ::insert(const key_type &k, valueU &&m)
939
955
num++;
940
956
}
941
957
942
- // / Replace element, element must exist in map
943
- // /
944
- // / Complexity:
945
- // / - Worst case: O(H * S + M)
946
- // / - Best case: O(H)
947
- // /
948
- // / \param k: The key of the element to insert
949
- // / \param m: The mapped value to replace the old value with
950
958
SHARING_MAPT4 (valueU, void )
951
959
::replace(const key_type &k, valueU &&m)
952
960
{
@@ -963,14 +971,6 @@ ::replace(const key_type &k, valueU &&m)
963
971
lp->set_value (std::forward<valueU>(m));
964
972
}
965
973
966
- // / Find element
967
- // /
968
- // / Complexity:
969
- // / - Worst case: O(H * log(S) + M)
970
- // / - Best case: O(H)
971
- // /
972
- // / \param k: The key of the element to search
973
- // / \return optionalt containing a const reference to the value if found
974
974
SHARING_MAPT2 (optionalt<std::reference_wrapper<const , mapped_type>>)::find(
975
975
const key_type &k) const
976
976
{
0 commit comments