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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:13:57+00:00 2026-05-13T18:13:57+00:00

This is related to this question I have a vector of points that will,

  • 0

This is related to this question

I have a vector of points that will, for instance, store 100K+ points.

std::vector<Point> point_vec; 

I want to check if a position (x, y, z) to be added is already in point_vec (represented by an instance of class Point ). The following function will check this (in a for loop)

bool samePoints(const Point& p1, 
                const double x1, 
                const double y1, 
                const double z1) {

     return fabs(p1.x - x1) < EPSILON &&
            fabs(p1.y - y1) < EPSILON &&
            fabs(p1.z - z1) < EPSILON;
}

But, I guess checking if x in list/ vector will be a costly operation. I want to know if there is a better way to check if a) Points are equal (perhaps an operator “=” on class Point?? and (b) Is there some other , better data structure than `vector’ that I should make use of. OR if there is an operation on vector that will speed up checking for ‘same points’

For (b) please note that I need to std::sort these points as well. So any other data structure that you may suggest should be able to sort these points.

UPDATE

I want the points in the sorted state only. It is just that vector doesn’t sort those (so I need to perform a sort operation. Should I use std::set<Point> point_set instead of instead of std::vector <Point> point_vec ? IF SO: Is adding each point to a set a costly operation ? Or ‘vector’ sorting that I do in the end turns out costlier overall?

  • 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-05-13T18:13:57+00:00Added an answer on May 13, 2026 at 6:13 pm

    Is the collection of points always sorted or must it sometimes be in an unsorted state? If the former, a std:;set of points will be fast to determine if a point is already there, and will maintain the points in sorted order. You would have to supply a suitable ordering function (not an equality one), which may be faster than your equality test.

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

Sidebar

Related Questions

I have a question related to this one . I don't want to do
Another question related to this one . I have a List<SortableObjects> that is the
I have searched here, GooBingHooVista'd the world and read this related question for VS
I have a question related to this one : I'm trying to attach an
This is a related to a previous question I have asked here, see the
There is another possibly related question on this but it didn't have answers and
This question is related to database/RDBMS where i have little knowledge regarding performance and
This question is kind of related to another question but I have a specific
this time i have a simple question: I have one table, related with himself
This question is related to awk, I suppose. I have no experience with awk.

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.