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 9125617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:50:45+00:00 2026-06-17T06:50:45+00:00

If a timestamp is NOT in a map stored with timestamps I would like

  • 0

If a timestamp is NOT in a map stored with timestamps I would like to find the closest matching timestamp in the map and use the closest value as a key. I have the basic structure setup for what I’m trying to do i’m just not sure how to find the nearest timestamp

typedef std::map<std::string,int>  Map;
Map::iterator it;
Map my_map;

my_map["2010-01-26 17:02:12"]= 1;
my_map["2010-01-25 08:55:29"]= 2;
my_map["2010-01-24 08:55:29"]= 3;

string timestamp = "2010-01-24 08:55:30"; // would return 3
string timestamp1 = "2010-01-27 01:55:30"; // would return 1

  it = my_map.find(timestamp); 
     if(it == my_map.end()){
       //not sure how to approach this
   }    

update

I’m trying to avoid converting a fairly large code base from std::string to uint64_t although it would increase performance, it’s not that big of an issue,

I can’t get the std::map::lower_bound or std::map::upper_bound solutions to work
here is my attempt on IDE ONE,

http://ideone.com/MnRLIH

  • 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. Editorial Team
    Editorial Team
    2026-06-17T06:50:46+00:00Added an answer on June 17, 2026 at 6:50 am

    You can probably get what you need with std::map::lower_bound or std::map::upper_bound, either of which is O(log N) complexity.


    Also, strongly consider storing your timestamps as, say, a uint64_t rather than a string. This would greatly reduce the amount of computation to compare and process.

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

Sidebar

Related Questions

I have a table with 3 fields: ID (not unique, not primary key) timestamp
I have a map of string-rule pairs and I would like to create a
I have a database table containing dates (`date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00').
I have a table with a field: 'last_modified - timestamp NOT NULL' I set
I've got a table like so: CREATE TABLE IF NOT EXISTS grades(_id, timestamp, extra);
Should timestamps always use UTC (as in 2012-06-14T10:32:11+00:00 ) and not local time (as
Since TIMESTAMP in mysql is stored as a 32bit value representing the time interval
I have this DB design: CREATE TABLE report ( ID MEDIUMINT PRIMARY KEY NOT
I am trying to use the following code, which I have not been able
Zen Timestamp Plugin does not work for me with Matrix builds on Windows when

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.