Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-106176

Q(Multi)Hash is missing equal_range()

    XMLWordPrintable

    Details

    • Type: Suggestion
    • Status: Open
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None
    • Story Points:
      8
    • Sprint:
      Foundation PM Staging

      Description

      Q(Multi)Hash, unlike QMap containers, and unlike std::unordered_map, lacks the equal_range() function. Currently, the only option to find the range of equal elements in a QMultiHash is to loop over the successors of the result of find(), which is not very nice.

      Acceptance criteria: The following test passes and has complexity linear in N = std::distance(b, e):

      QMultiHash<int, QString> h = {
          {0, "zero"},
          {1, "one"},
          {1, "uno"},
          {2, "two"},
      };
      auto r = h.equal_range(1);
      static_assert(std::is_same_v<decltype(r.first), QMultiHash<int, QString>::iterator>);
      static_assert(std::is_same_v<decltype(r.second), QMultiHash<int, QString>::iterator>);
      QCOMPARE_NE(r.first, h.end());
      QCOMPARE_NE(r.second, h.end());
      QCOMPARE_NEW(r.first, r.second);
      QCOMPARE_EQ(std::distance(r.first, r.second), 2);
      QCOMPARE_EQ(r.first.key(), 1);
      QCOMPARE_EQ(std::next(r.first).key(), 1);
      h.erase(r.first, r.second); // QTBUG-106175
      QMultiHash<int, QString> res = {{0, "zero"), {2, "two"}};
      QCOMPARE_EQ(h, res);
      

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              cnn Qt Core & Network
              Reporter:
              mmutz Marc Mutz
              PM Owner:
              Vladimir Minenko Vladimir Minenko
              RnD Owner:
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes