如何快速排序位集矢量? [英] How to sort a bitset vector quickly?

查看:83
本文介绍了如何快速排序位集矢量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想排序一个bitset向量(第1位>位0),而它似乎是bitset

没有<或者>操作。我试图用一个循环逐个比较每个

位,但它的速度令人难以忍受。有什么建议吗?

Hi all,
I want to sort a bitset vector ( bit 1 > bit 0 ), while it seems bitset
doesn''t have < or > operation. I tried to use a loop to compare each
bit one by one but it''s unbearably slow. Any suggestion?

推荐答案

< ha ********* @ gmail.com>在消息中写道

news:11 ********************** @ g14g2000cwa.googlegr oups.com ...
<ha*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
大家好,
我想排序一个bitset向量(第1位>第0位),而它似乎是bit /
没有<或者>操作。我试图用一个循环来逐个比较每个位,但它的速度令人难以忍受。有什么建议吗?
Hi all,
I want to sort a bitset vector ( bit 1 > bit 0 ), while it seems
bitset
doesn''t have < or > operation. I tried to use a loop to compare each
bit one by one but it''s unbearably slow. Any suggestion?



你可以计算零的数量并构建一个新的bitset,

你之前计算的零的数量,然后是其余的(确切地说

数字取决于原始bitset的大小减去数字

的零)。


hth

-

jb


(rot13中的回复地址,先解读)


You could count the number of zeros and construct a new bitset, with
the number of zeros you counted before and then the rest of ones (exact
number is determined by the size of the original bitset minus the number
of zeros).

hth
--
jb

(reply address in rot13, unscramble first)


* ha*********@gmail.com
我想对一个bitset向量进行排序(第1位>第0位),而它似乎是bitset
没有<或者>操作。我试图用一个循环来逐个比较每个位,但它的速度令人难以忍受。任何建议?
I want to sort a bitset vector ( bit 1 > bit 0 ), while it seems bitset
doesn''t have < or > operation. I tried to use a loop to compare each
bit one by one but it''s unbearably slow. Any suggestion?




假设这是一个std :: vector<的std ::位集< N> >:


std :: sort(v.begin(),v.end(),bitsetLess< n>);


其中''bitsetLess'是例如


模板< unsigned n>

bool bitsetLess(std :: bitset< n> const& left,std :: bitset< n> const& right)

{

返回left.to_ulong()< right.to_ulong();

}


-

答:因为它弄乱了人们通常阅读的顺序文字。

问:为什么这么糟糕?

A:热门帖子。

问:什么是最烦人的事情在usenet和电子邮件中?



Assuming this is a std::vector< std::bitset<n> >:

std::sort( v.begin(), v.end(), bitsetLess<n> );

where ''bitsetLess'' is e.g.

template< unsigned n >
bool bitsetLess( std::bitset<n> const& left, std::bitset<n> const& right )
{
return left.to_ulong() < right.to_ulong();
}

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


ha *** *****@gmail.com 在摊位墙上潦草地写道:
ha*********@gmail.com scribbled on the stall wall:
大家好,我想排序一个bitset向量(第1位>位0) ,虽然它似乎有点无法
没有<或者>操作。我试图用一个循环来逐个比较每个位,但它的速度令人难以忍受。有什么建议吗?
Hi all,
I want to sort a bitset vector ( bit 1 > bit 0 ), while it seems bitset
doesn''t have < or > operation. I tried to use a loop to compare each
bit one by one but it''s unbearably slow. Any suggestion?




为什么?!


bitsets的全部目的是它们通常是位置

依赖并在重新订购时失去意义。


重新考虑你这样做的理由。

-

double 2.8 Ghz Xeon; 2GB RAM; 500GB ATA-133; nVidia供电

Linux 2.6.10;的glibc-2.3.5;供应商中立的家庭酿造装置


----这条线之后的任何东西都是新闻服务器添加的令人厌恶的CRAP ----

---直接联系新闻馈送和互联网服务提供商捎带他们抱怨----

---- ==通过Newsfeeds.Com发布 - 无限制 - 未经审查 - 安全使用网新闻== ----
http://www.newsfeeds.com 世界排名第一的新闻组服务! 120,000多个新闻组

---- =东海岸和西海岸服务器农场 - 通过加密实现全隐私= ----



WHY?!

the whole purpose of bitsets is that they are generally position
dependent and lose their meaning when reordered.

rethink your reason for doing this.
--
dual 2.8Ghz Xeon; 2GB RAM; 500GB ATA-133; nVidia powered
Linux 2.6.10; glibc-2.3.5; vendor neutral home-brewed installation

----anything after this line is ANNOYING CRAP that the newsserver adds ----
---directly contact newsfeeds and ISPs that piggy back them to complain----
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----


这篇关于如何快速排序位集矢量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆