不是32位是30位,,写顺手了。。 ---------------------------------- [email protected] [email protected]
2009/9/23 msmouse <[email protected]> > 不是15位十进制数,是32位二进制 只是我没把1234写成 0b00 0b01 0b10 0b11,没把$index*4写成$index<<2而已。。 > ---------------------------------- > [email protected] > [email protected] > > > 2009/9/23 空格 <[email protected]> > > 我大概明白你的意思了。这样实际是用一个15位的十进制数字来代替一个15个字母的字符串。确实这样至少要4G内存。 >> >> >> On 9月23日, 下午5时40分, msmouse <[email protected]> wrote: >> > # 用一个1G项的数据计数 >> > my @count_of; >> > # 字符和数字的转换表 >> > my %code_of = ( >> > A=>0, >> > G=>1, >> > C=>2, >> > T=>3 >> > ); >> > >> > # 计算一个15字符的字串对应的下标,每个字符占用两个二进制位 >> > my $index = 0; >> > for $char (split q[], $str) { # 按字符分开 >> > $index *= 4; # 左移两位 >> > $index += $key{$char}; # 将当前位加入末两位 >> > >> > } >> > >> > # 计数: >> > $count_of[$index] += 1; >> > >> > 打印出来需要通过一个循环取末两位、右移两位的方法取得下标对应的实际字符串 >> > >> > 不知道这样说清楚没有 :) >> > 但是如昨天的讨论所说 这个数组本身就至少占4G内存(假定每项是一个4字节的int),因此在perl中完全在内存中进行是不大可行的。 >> > >> > ---------------------------------- >> > [email protected] >> > [email protected] >> > >> > 2009/9/23 空格 <[email protected]> >> > >> > > 我昏了,之前我把00,01,10,11理解成十进制的数字了。 >> > > 就是说, >> > > 当取到一个字串赋给$key之后, >> > > $key=~s{A}{0}g; >> > > $key=~s{G}{1}g; >> > > $key=~s{T}{2}g; >> > > $key=~s{C}{3}g; >> > > 再用 exists(%hash{$key}); 检查是否有特定键值。是这样的吧? >> > >> > > On 9月23日, 上午11时17分, msmouse <[email protected]> wrote: >> > > > 就是这个意思。前面agentzh说: >> > > > ”事先约定 A,T,G,C 分别对应 00, 01, 10, 11,即 2 个比特的数值。“ >> > > > 即用两个位表示一个字符,15个字符即是30位。30个二进制位即是15个4进制位 >> > > > ---------------------------------- >> > > > [email protected] >> > > > [email protected] >> >> >> > --~--~---------~--~----~------------~-------~--~----~ 您收到此信息是由于您订阅了 Google 论坛“PerlChina Mongers 讨论组”论坛。 要在此论坛发帖,请发电子邮件到 [email protected] 要退订此论坛,请发邮件至 [email protected] 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛 -~----------~----~----~----~------~----~------~--~---
