简体   繁体   English

push :: sort对某些值进行了错误排序

[英]thrust::sort missorts some values

I have some objects I want to sort on a host_vector, These objects have a < Operator defined, which compares the Id (a integer) of the objects. 我有一些要在host_vector上排序的对象,这些对象定义了<运算符,用于比较对象的ID(整数)。 The vector contains pointers to the objects. 向量包含指向对象的指针。

If I perform thrust::sort(object_vector.begin(),object_vector.end()); 如果我执行thrust::sort(object_vector.begin(),object_vector.end()); and then iterate through the vector to print the Id's I get: 然后遍历向量以打印我得到的ID:
48, 49, 0, 1, [..], 47, 50, [..]

If I perform std::sort(object_vector.begin(),object_vector.end()); 如果我执行std::sort(object_vector.begin(),object_vector.end()); I get the Id's in order. 我按顺序得到ID。 I have no clue why these two values are out of order (they are always the same for the same number of objects). 我不知道这两个值为何乱序(对于相同数量的对象,它们总是相同的)。
The objects according to this Id's have nothing special. 根据此ID的对象没有什么特别的。

stable_sort doesn't change anything. stable_sort不变。 Sorting a vector with the Id's works. 用ID的作品对向量进行排序。 Operators: 运营商:

bool operator<(MultiLegBase* other){return (this->getID()<other->getID());}
bool operator==(MultiLegBase* other){return this->getID()==other->getID();}
bool operator>(MultiLegBase* other){return this->getID()>other->getID();}
virtual unsigned int const getID(return m_Id;)

I looked again on my operators and got what is wrong. 我再次查看了操作员,发现出了什么问题。 The this->getID() construct fails. this->getID()构造失败。 Because operator>() , is not called with two pointer arguments (as far as I understand). 因为operator>()不使用两个指针参数调用(据我所知)。 I solved it with an functor: [..] bool operator()(Multibaseleg* M,Multibaseleg* N){return (M->getID()<N->getID());}[..] 我用函子解决了这个问题: [..] bool operator()(Multibaseleg* M,Multibaseleg* N){return (M->getID()<N->getID());}[..]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM