在STLport下双重排序的问题
要处理一些大的文本文件,7.8十兆,有100万行数据. 格式如下:
time a b
07:01:31:22:28:171631174
07:01:31:23:23:18338
07:01:31:23:24:061123
07:01:31:23:37:561291742
07:01:31:23:52:51312
07:02:01:00:04:47321225
07:02:01:00:06:04128993
07:02:01:00:07:26715871
07:02:01:00:07:59699437
上面是file中一段数据。 先根据time选择要处理文件的长度,比如说07:01:31:22:28:17到07:02:31:22:28:17这一个月的。
然后对a,b两列处理。
1 compare a with b, if a> b, then change a and b
2 if a == b, then delete this entry
3 sort column a in increasing order //a移动的时候它对应的b跟着一起移动。 整个entry(a,b)跟着移动
then sort column b in increasing order for every value of a
4 delete same entry eg: 12 34
12 34 //delete
12 34 //delete
just keep one entry.
The last file is like this: (no time column)
a b
1 2
1 3
1 4
2 3
2 4
2 5
2 6
3 4
3 5
3 6
我比较怵指针和链表,所以想用STL封装好的。
struct email
{
srting sent_time;
long int sender;
long int receiver;
};
vector <email> email
因为考虑到文件大小不定,就想用STLport的vector,后面又牵扯到根据a,b的双重排序,不晓得sort函数支持不支持。脑子乱七八糟又想用multimap或者hash table,根据key/value来排序和删除。
上面的结构体也许也用不到,读文件每读一行,就抽取a,b放在vector或者map里。那个时间范围的截取,我需要用强制类型转换把字符串型弄成data吗?这个怎么处理呢?我自己思路挺乱的,请各位帮忙指点一下。多谢!
BTW:我用的是VC6+SP6+STLport4.6.2
[解决办法]
struct email
{
srting sent_time;
long int sender;
long int receiver;
};
-----
struct email
{
bool operator < (const email &th)
{
return this-> sender < th.sender;//假设以sender排序
}
srting sent_time;
long int sender;
long int receiver;
};
然后把字段放到vector里就可以直接排序了
[解决办法]
template <class RandomAccessIterator, class Pr>
void sort(
RandomAccessIterator _First,
RandomAccessIterator _Last,
BinaryPredicate _Comp <==========这个参数就是比较规则函数
);
当然你也可以采取结构体重载operator <这种做法