如何减少冗余的记录?

marshallzh 2010-08-10 05:35:48
语言是C#。有一个程序每隔1秒读入当前的netstat信息,包含:时间戳, source IP, destination IP 等。
根据实际观察,发现有很多记录的 source IP, destination IP 等信息完全相同,只有时间戳不同。

有没有什么好的数据结构和算法可以去除这些冗余,只把不同的记录写到txt文件中?

谢谢。
...全文
120 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
marshallzh 2010-08-17
  • 打赏
  • 举报
回复
多谢,dictionary is better than Hashtable!

[Quote=引用 2 楼 sbwwkmyd 的回复:]

运行时状态可以用System.Collections.Generic.Dictionary
C# code

public struct ipv4s
{
public uint sourceIP;
public uint destinationIP;
}
System.Collections.Generic.Dictionary<ipv4s,List<时间戳类型>>


当然也可以用红黑树……
[/Quote]
marshallzh 2010-08-17
  • 打赏
  • 举报
回复
我尝试用了Hashtable
多谢!

[Quote=引用 1 楼 saramand9 的回复:]

C#中有没有类似C++ STL中MAP(映射,红黑树也可以实现)这样的容器呢?
以source IP, destination IP 为关键字,每次进来判重就可以了,
每次判重复杂度 log(n),n是map中元素个数,

不知道这样是不是可以满足你的要求?
[/Quote]
showjim 2010-08-10
  • 打赏
  • 举报
回复
运行时状态可以用System.Collections.Generic.Dictionary

public struct ipv4s
{
public uint sourceIP;
public uint destinationIP;
}
System.Collections.Generic.Dictionary<ipv4s,List<时间戳类型>>

当然也可以用红黑树。

至于记录到文件,如果是随时更新的话用数据库吧,自己写B+树比较麻烦。如果是批量只写的话,这样的简单的数据自己写一个序列化过程就可以了。
saramand9 2010-08-10
  • 打赏
  • 举报
回复
C#中有没有类似C++ STL中MAP(映射,红黑树也可以实现)这样的容器呢?
以source IP, destination IP 为关键字,每次进来判重就可以了,
每次判重复杂度 log(n),n是map中元素个数,

不知道这样是不是可以满足你的要求?

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧