BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / soft-design / #26208同步于 2008/6/8
该镜像源已超过 30 天没有更新,可能在源站已被删除。
SoftDesign机器人发帖

ipv6地址类by包子

coolwc
2008/6/8镜像同步12 回复
class InetAddress128 { public: InetAddress128(); ~InetAddress128(); unsigned address[4]; int prefix; bool right(unsigned int n);//左移 bool left(unsigned int n);//右移 InetAddress128 subbit128(unsigned begin,unsigned int len); //截取位串 InetAddress128 operator^(InetAddress128);//异或 unsigned int operator%(unsigned int max);//求余 bool operator<= (const InetAddress128) const;//小于等于 bool operator>= (const InetAddress128) const;//大于等于 InetAddress128 high(int prefix);//前缀范围的最大值 InetAddress128 low(int prefix);// 前缀范围的最小值 bool parse(char* str);//解析字符串形式的地址 int prefixlen();//前缀长度 void left32(int n); void right32(int n); void print(); char* tostring() const;//生成字符形式的地址 InetAddress128 operator-(const InetAddress128);//减法 InetAddress128 operator/(const unsigned int n);//除法 InetAddress128 operator+(const InetAddress128 addr2);//加法 bool const operator==(const InetAddress128 addr2);//相等 bool const operator>(const unsigned int n); //大于(与int比较) bool const operator<(const InetAddress128 addr2);//小于 bool const operator>(const InetAddress128 addr2);//大于 }; 附件(11.1KB) inetaddress128.rar
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
coolwc机器人#1 · 2008/6/8
性能低的要死 别奢望用做大吞吐的地方 【 在 coolwc (北邮の包子) 的大作中提到: 】 : class InetAddress128 : { : public: : ...................
coolfantasy机器人#2 · 2008/6/9
我不懂IPv6。。。也不懂C++。。。。。 不过我觉得代码风格还可以改善 bool const InetAddress128::operator>(const InetAddress128 addr2) { for (int i = 0; i < 4; ++i) { if (addr2.address[i] < address[i]) { return true; } else if (addr2.address[i] > address[i]) { return false; } } return false; } 【 在 coolwc 的大作中提到: 】 : 别光看 指导下
coolwc机器人#3 · 2008/6/9
少循环3次也是性能。。 【 在 coolfantasy (Cool) 的大作中提到: 】 : 我不懂IPv6。。。也不懂C++。。。。。 : 不过我觉得代码风格还可以改善 : bool const InetAddress128::operator>(const InetAddress128 addr2) : ...................
rabbit机器人#4 · 2008/6/9
感觉应该可以有的地方用传引用吧?可以快些。 就像coolfantasy贴的那段,不一定非要传值。
rabbit机器人#5 · 2008/6/9
怎么了? 没看出来什么问题…… 那个函数写的是const,应该不会改变私有成员对象吧,而且也只是比较。 为什么不能写成&? =。= 【 在 yegle 的大作中提到: 】 : 这是在恶意传播谣言么?
yegle机器人#6 · 2008/6/9
你的回复的标题 我记得你已经用这个标题很久了 【 在 rabbit (贝贝) 的大作中提到: 】 : 怎么了? : 没看出来什么问题…… : 那个函数写的是const,应该不会改变私有成员对象吧,而且也只是比较。 : ...................
rabbit机器人#7 · 2008/6/9
这下我都改回来了,被别人粘贴复制了…… 代码的风格比较容易出错,尤其是for里面if elseif的地方 还有,要性能的话,可以多用移位。 那个bigInt好大啊,看不下去了……
coolwc机器人#8 · 2008/6/9
把用bigint的地方全改成位运算 性能肯定要好点 【 在 rabbit (贝贝) 的大作中提到: 】 : 这下我都改回来了,被别人粘贴复制了…… : 代码的风格比较容易出错,尤其是for里面if elseif的地方 : 还有,要性能的话,可以多用移位。 : ...................
rabbit机器人#9 · 2008/6/9
尽量多用string吧,比char*要好一点。 还有cout cin之类的。 虽然我现在也很不习惯,正在慢慢改。 可能是最近被 T I C++ 洗脑了。