Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using Qt to generate stringlist combinations
Forum Updated to NodeBB v4.3 + New Features

Using Qt to generate stringlist combinations

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • kalmaK Offline
    kalmaK Offline
    kalma
    wrote on last edited by
    #1

    Hi

    How can I use Qt to write a function "nemely, generator" that returns combinations of argument sequences "string lists" e.g. combine(('A','B'),('1','2','3')) will return [('A','1'), ('A','2'), ('A','3'), ('B','1'), ('B','2'), ('B','3')] on demand by calling next() or something i.e. the function will not create the whole list of combinations in memory at once.
    The function is to be applicable to any number of sequences i.e. combine(Sequence1, Sequence2, Sequence3, ...)

    Can anybody help me?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jake007
      wrote on last edited by
      #2

      Qt hasn't got functionality for this ( as far as I know), but you can easily write your own class.
      You can pass a number of desired sequence combination and then calculate string position.
      For next() function, you'll need a vector of integers ( if you have n-number of sequences) for number of string in list and another one for location in each list.
      "QString":http://qt-project.org/doc/qt-4.8/QString.html and "QStringList":http://qt-project.org/doc/qt-4.8/QStringList.html documentation.

      Hope it helped ;)
      Regards,
      Jake


      Code is poetry

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        I would write an iterator class for this, so you can re-use the code later on in generic algorithms. In this case, the iterator would work on n (>=1) containers, instead of one container.

        Your main issue, I think, is the return value for your iterator. That value somehow has to contain any number of values, and that is tricky, especialy if they can be of different types. If they are all the same type, you could create a single accessor method that takes an index for the container, and just returns the value, so that would simplify the issue a lot.

        Could you describe your constraints a bit better? The containers, what do they contain? Are they all of the same type? Are they random access, or do they have contraints like forward-iterators only?

        1 Reply Last reply
        0
        • kalmaK Offline
          kalmaK Offline
          kalma
          wrote on last edited by
          #4

          Hi Jake, can you please put a sample code here, just the main idea.
          Thanks in advance

          [quote author="Jake007" date="1331986938"]Qt hasn't got functionality for this ( as far as I know), but you can easily write your own class.
          You can pass a number of desired sequence combination and then calculate string position.
          For next() function, you'll need a vector of integers ( if you have n-number of sequences) for number of string in list and another one for location in each list.
          "QString":http://qt-project.org/doc/qt-4.8/QString.html and "QStringList":http://qt-project.org/doc/qt-4.8/QStringList.html documentation.

          Hope it helped ;)
          Regards,
          Jake
          [/quote]

          1 Reply Last reply
          0
          • kalmaK Offline
            kalmaK Offline
            kalma
            wrote on last edited by
            #5

            Hi Andre
            This sounds promising! for now my main issue is the recursion in itself!
            BTW the sequences are of QString type to make it easier.

            The containers, what do they contain?
            They are lists of QString type.

            Are they all of the same type?
            Yes, QString.

            Are they random access, or do they have contraints like forward-iterators only?
            Forward-iterators only

            Thanks for the reply!

            [quote author="Andre" date="1332008101"]I would write an iterator class for this, so you can re-use the code later on in generic algorithms. In this case, the iterator would work on n (>=1) containers, instead of one container.

            Your main issue, I think, is the return value for your iterator. That value somehow has to contain any number of values, and that is tricky, especialy if they can be of different types. If they are all the same type, you could create a single accessor method that takes an index for the container, and just returns the value, so that would simplify the issue a lot.

            Could you describe your constraints a bit better? The containers, what do they contain? Are they all of the same type? Are they random access, or do they have contraints like forward-iterators only?
            [/quote]

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jake007
              wrote on last edited by
              #6

              Brain to terminal ( not tested and this may be completely wrong ;) ):
              @// input is index of desired sequnce
              QString CNemelyGen::getSequnceNr(int sqNr)
              {
              // storage for indexes of strings
              QVector<int> tmpIndex;

              // size list -> class variable QVector, to store sizes of strings
              for(int i=0; i<sizeList.size(); i++)
              {
              // Calculates index of current argument sequnces
              tmpIndex.append(sqNr%sizeList[i]);
              sqNr%=sizeList[i];
              }

              // String that will be returned
              QString retSqString;

              // generates string based on index
              for(int i=0; i<stringList.size(); i++)
              {
              // Gets character in each string and append it at end of return string
              retSqString.append(stringList.at[i].at(tmpIndex[i]));
              }

              return retSqString;
              }@

              And as for next(), add tmpIndex to class instead of function. And only add one to last index ( make sure to check if last index isn't maxed out ( last possible index), if it is, reset it to zero, and ++ one before. And check again if it's the last one etc...)

              Hope that provided comments will be enough.

              Regards,
              Jake


              Code is poetry

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved