これは私のコードです:次のようであるC++のSTL make_heapとPRIORITY_QUEUEは異なる出力に与え
std::priority_queue<SimpleCycle,
std::vector<SimpleCycle>,
SimpleCycle> pq;
pq.push(cycle1);
pq.push(cycle2);
pq.push(cycle4);
std::cout << pq.top().to_string() << std::endl;
std::vector<SimpleCycle> pq2{ cycle1, cycle2, cycle4 };
std::make_heap(pq2.begin(), pq2.end(), SimpleCycle());
std::cout << pq2.front().to_string() << std::endl;
コンパレータSimpleCycle
のために:
const bool SimpleCycle::operator()(SimpleCycle& L, SimpleCycle& R) const
{
float a = L.avg_latency();
float b = R.avg_latency();
//Allow an error rate of 0.0000000001
//Ref. The Art of Computer Programming: Seminumerical algorithms(Page 128)
return (b - a) > ((fabs(a) < fabs(b)
? fabs(b) : fabs(a)) * (0.0000000001));
}
機能がfloat
を返しavg_latency()
。しかし、私は同じ同じ入力の場合に異なる出力を得ます。おそらく何が間違っていますか?
は、私が行っていない...遊んで丸め誤差があるかもしれません反例が生成されますが、比較演算子が標準によって厳密な弱い順序を提供しない可能性があるので、どのような動作も期待できます。 –