Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 93029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:16:48+00:00 2026-05-10T23:16:48+00:00

I’m currently working on a DNA database class and I currently associate each row

  • 0

I’m currently working on a DNA database class and I currently associate each row in the database with both a match score (based on edit distance) and the actual DNA sequence itself, is it safe to modify first this way within an iteration loop?

typedef std::pair<int, DnaDatabaseRow> DnaPairT; typedef std::vector<DnaPairT>          DnaDatabaseT;  // ....  for(DnaDatabaseT::iterator it = database.begin();     it != database.end(); it++) {     int score = it->second.query(query);     it->first = score; } 

The reason I am doing this is so that I can sort them by score later. I have tried maps and received a compilation error about modifying first, but is there perhaps a better way than this to store all the information for sorting later?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:16:49+00:00Added an answer on May 10, 2026 at 11:16 pm

    To answer your first question, yes. It is perfectly safe to modify the members of your pair, since the actual data in the pair does not affect the vector itself.

    edit: I have a feeling that you were getting an error when using a map because you tried to modify the first value of the map’s internal pair. That would not be allowed because that value is part of the map’s inner workings.

    As stated by dribeas:

    In maps you cannot change first as it would break the invariant of the map being a sorted balanced tree

    edit: To answer your second question, I see nothing at all wrong with the way you are structuring the data, but I would have the database hold pointers to DnaPairT objects, instead of the objects themselves. This would dramatically reduce the amount of memory that gets copied around during the sort procedure.

    #include <vector> #include <utility> #include <algorithm>   typedef std::pair<int, DnaDatabaseRow> DnaPairT; typedef std::vector<DnaPairT *>       DnaDatabaseT;  // ...  // your scoring code, modified to use pointers void calculateScoresForQuery(DnaDatabaseT& database, queryT& query) {     for(DnaDatabaseT::iterator it = database.begin(); it != database.end(); it++)     {         int score = (*it)->second.query(query);         (*it)->first = score;     } }  // custom sorting function to handle DnaPairT pointers bool sortByScore(DnaPairT * A, DnaPairT * B) { return (A->first < B->first); }  // function to sort the database void sortDatabaseByScore(DnaDatabaseT& database) {     sort(database.begin(), database.end(), sortByScore); }  // main int main() {     DnaDatabaseT database;      // code to load the database with DnaPairT pointers ...      calculateScoresForQuery(database, query);     sortDatabaseByScore(database);      // code that uses the sorted database ... }

    The only reason you might need to look into more efficient methods is if your database is so enormous that the sorting loop takes too long to complete. If that is the case, though, I would imagine that your query function would be the one taking up most of the processing time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I am currently running into a problem where an element is coming back from
I am writing an app with both english and french support. The app requests
I have a reasonable size flat file database of text documents mostly saved in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.