我尝试使用a std::set以便在容器中包含唯一元素.
由于我有3D对象:
Class Object3D{
private:
float x;
float y;
float z;
}
Run Code Online (Sandbox Code Playgroud)
那些对象在等于 (A.x==B.x && A.y==B.y && A.z==B.z).
在std :: set实现中有一个元素 A==B if (!(A < B) && !(B>A)).
我的比较是不可能的...我试图超载==运算符.
我选择set container来比较我打电话时的值insert(a).我std::vector v和他的迭代器做了类似的事情:
if(!(A).inVector()){
v.push_back(A);
}
Run Code Online (Sandbox Code Playgroud)
同
bool inVector(){
for(itr = v.begin();itr != v.end();itr++){
if(this->x==(*itr)->x && this->y==(*itr)->y && this->z==(*itr)->z){
return true;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
检查每个对象(10000-100000)的复杂性是昂贵的.
有人有想法吗?