|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4323" status="New"> |
| 5 | +<title>`hive::unique` time complexity should incorporate potential block removal complexity</title> |
| 6 | +<section> |
| 7 | +<sref ref="[hive.operations]"/> |
| 8 | +</section> |
| 9 | +<submitter>Matt Bentley</submitter> |
| 10 | +<date>24 Aug 2025</date> |
| 11 | +<priority>99</priority> |
| 12 | + |
| 13 | +<discussion> |
| 14 | +<p> |
| 15 | +Currently we specify for `erase` <sref ref="[hive.modifiers]"/> p16: |
| 16 | +</p> |
| 17 | +<blockquote><p> |
| 18 | +"<i>Complexity:</i> Linear in the number of elements erased. Additionally, if |
| 19 | +any active blocks become empty of elements as a result of the function |
| 20 | +call, at worst linear in the number of element blocks." |
| 21 | +</p></blockquote> |
| 22 | +<p> |
| 23 | +This is to allow for potential `hive` implementations as vectors of |
| 24 | +pointers to blocks, as opposed to linked-lists of blocks (reference |
| 25 | +implementation approach). In that scenario removing a block would |
| 26 | +involve a vector erasure and subsequent pointer-to-block relocations. |
| 27 | +swap-and-pop of block pointers would not work as this would re-arrange |
| 28 | +the sequence during erasure. Anyway, we have neglected to apply this |
| 29 | +same complexity to `hive::unique`. It would be rare that this would occur |
| 30 | +for `unique`, as it would involve (1) a block <i>A</i> with only one non-erased |
| 31 | +element left in it and (2) a block <i>B</i> preceding/following block |
| 32 | +<i>A</i> in the sequence, whose last/first element is equal to the element |
| 33 | +in block <i>A</i>. But it is possible, so the same consideration in terms |
| 34 | +of time complexity applies. |
| 35 | +</p> |
| 36 | +<blockquote class="note"> |
| 37 | +<p> |
| 38 | +This is a separate but related issue to LWG <iref ref="4320"/>, but it would |
| 39 | +affect the outcome wording of that issue for `unique`. |
| 40 | +</p> |
| 41 | +</blockquote> |
| 42 | +</discussion> |
| 43 | + |
| 44 | +<resolution> |
| 45 | +<p> |
| 46 | +This wording is relative to <paper num="N5014"/>. |
| 47 | +</p> |
| 48 | + |
| 49 | +<ol> |
| 50 | + |
| 51 | +<li><p>Modify <sref ref="[hive.operations]"/> as indicated:</p> |
| 52 | + |
| 53 | +<blockquote class="note"> |
| 54 | +<p> |
| 55 | +[<i>Drafting note:</i> If issue LWG <iref ref="4320"/> is decided to be acted upon and |
| 56 | +the proposed solution accepted, the proposed complexity wording becomes: |
| 57 | +</p> |
| 58 | +<blockquote><p> |
| 59 | +-11- <i>Complexity</i>: If `empty()` is `false`, exactly `size() - 1` applications |
| 60 | +of the corresponding predicate, otherwise no applications of the predicate. |
| 61 | +<ins>For each element erased as a result of this function call, at worst <tt>𝒪(log n)</tt> |
| 62 | +in the capacity of each block containing the element. Additionally, if any active blocks become |
| 63 | +empty of elements as a result of the function call, at worst linear in the number of element |
| 64 | +blocks.</ins> |
| 65 | +</p></blockquote> |
| 66 | +<p> |
| 67 | +] |
| 68 | +</p> |
| 69 | +</blockquote> |
| 70 | + |
| 71 | + |
| 72 | +<blockquote> |
| 73 | +<pre> |
| 74 | +template<class BinaryPredicate = equal_to<T>> |
| 75 | + size_type unique(BinaryPredicate binary_pred = BinaryPredicate()); |
| 76 | +</pre> |
| 77 | +<blockquote> |
| 78 | +<p> |
| 79 | +-7- <i>Preconditions</i>: […] |
| 80 | +<p/> |
| 81 | +-8- <i>Effects</i>: […] |
| 82 | +<p/> |
| 83 | +-9- <i>Returns</i>: […] |
| 84 | +<p/> |
| 85 | +-10- <i>Throws</i>: […] |
| 86 | +<p/> |
| 87 | +-11- <i>Complexity</i>: If `empty()` is `false`, exactly `size() - 1` applications |
| 88 | +of the corresponding predicate, otherwise no applications of the predicate. |
| 89 | +<ins>Additionally, if any active blocks become empty of elements as a result of the |
| 90 | +function call, at worst linear in the number of element blocks.</ins> |
| 91 | +<p/> |
| 92 | +-12- <i>Remarks</i>: […] |
| 93 | +</p> |
| 94 | +</blockquote> |
| 95 | +</blockquote> |
| 96 | + |
| 97 | +</li> |
| 98 | + |
| 99 | +</ol> |
| 100 | +</resolution> |
| 101 | + |
| 102 | +</issue> |
0 commit comments