BitMap算法 .net实现 用于去重并且排序,适用于大型权限管理 ,大数据去重排序
BitMap利用byte特性 针对排序+去重 最佳实践: 100万条数据的排序+去重用时200毫秒左右
- static void Main(string[] args)
- {
- int[] data = new int[];
- /*alias*/
- Random r = new Random();
- for (int i = ; i < data.Length; i++)
- {
- data[i] = r.Next(, );
- }
- Stopwatch stop = new Stopwatch();
- stop.Start();
- List<byte> lstbyte = new List<byte>();
- foreach (var item in data)
- {
- int unit = item / ;
- int index = item % ;
- if (lstbyte.Count <= unit)
- {
- lstbyte.AddRange(new byte[unit-lstbyte.Count + ]);
- }
- lstbyte[unit] = set_bit(lstbyte[unit], index + , true);
- }
- List<int> result = new List<int>();
- for (int i = ; i < lstbyte.Count; i++)
- {
- int currentIndex = i*;
- List<int> lstint = new List<int>();
- if (lstbyte[i] > )
- {
- /**
- * 这段代码用于判断,byte对应位置的值是否有1
- * 例如: 目标 byte:0010 0001
- * 0010 0001 & 0000 0001 结果为1则 第一位为1
- * 第二位比较方式就是目标byte和 0010 0001 & 0000 0010
- * 为避免频繁的装箱拆箱操作,这里不用通过 Math.Pow计算平2的平方立方来得到目标比较数。
- */
- int b = lstbyte[i] & 0x01;
- if (b == )
- {
- lstint.Add(currentIndex+);
- }
- b = lstbyte[i] & 0x02;
- if (b == )
- {
- lstint.Add(currentIndex + );
- }
- b = lstbyte[i] & 0x04;
- if (b == )
- {
- lstint.Add(currentIndex + );
- }
- b = lstbyte[i] & 0x08;
- if (b == )
- {
- lstint.Add(currentIndex + );
- }
- b = lstbyte[i] & 0x10;
- if (b == )
- {
- lstint.Add(currentIndex + );
- }
- b = lstbyte[i] & 0x20;
- if (b == )
- {
- lstint.Add(currentIndex + );
- }
- b = lstbyte[i] & 0x40;
- if (b == )
- {
- lstint.Add(currentIndex + );
- }
- b = lstbyte[i] & 0x80;
- if (b == )
- {
- lstint.Add(currentIndex + );
- }
- }
- result.AddRange(lstint);
- }
- stop.Stop();
- Console.WriteLine("结果数:"+result.Count);
- //foreach (var item in result)
- //{
- // Console.WriteLine(item);
- //}
- Console.WriteLine(string.Concat("时间:" ,stop.ElapsedMilliseconds ,"毫秒"));
- Console.ReadKey();
- }
- /// <summary>
- /// 设置某一位的值
- /// </summary>
- /// <param name="data"></param>
- /// <param name="index">要设置的位, 值从低到高为 1-8</param>
- /// <param name="flag">要设置的值 true / false</param>
- /// <returns></returns>
- static byte set_bit(byte data, int index, bool flag)
- {
- if (index > || index < )
- throw new ArgumentOutOfRangeException();
- int v = index < ? index : ( << (index - ));
- return flag ? (byte)(data | v) : (byte)(data & ~v);
- }
运行速度和待排序去重的最大数的大小有关系
BitMap算法 .net实现 用于去重并且排序,适用于大型权限管理 ,大数据去重排序的更多相关文章
- 大数据排序算法:外部排序,bitmap算法;大数据去重算法:hash算法,bitmap算法
外部排序算法相关:主要用到归并排序,堆排序,桶排序,重点是先分成不同的块,然后从每个块中找到最小值写入磁盘,分析过程可以看看http://blog.csdn.net/jeason29/article/ ...
- 大数据去重(data deduplication)方案
数据去重(data deduplication)是大数据领域司空见惯的问题了.除了统计UV等传统用法之外,去重的意义更在于消除不可靠数据源产生的脏数据--即重复上报数据或重复投递数据的影响,使计算产生 ...
- SAP ABAP将大数据量排序后输入到内表
要向内表读入3百50万条数据,如果一次读入就会产生运行错误,错误提示为,没有内存对于扩展 内表. 我考虑使用SELECT...INTO TABLE...PACKAGE SIZE 和ENDSELECT来 ...
- mysql排序,可以对统计的数据进行排序
sql SELECT a.*,b.name as address_name,b.tel as address_tel,b.province as address_province,b.city as ...
- java数组排序问题:array.sort()是从小到大排序,那么如何从大到小排序?
别告诉我从i=a.length开始打印然后i--!因为数组没变啊,只是打印顺序变了.有木有啥别的方法,除了冒泡插入选择.. nteger [] array=new Integer[]{1,2,3,4, ...
- php 大数据量及海量数据处理算法总结
下面的方法是我对海量数据的处理方法进行了一个一般性的总结,当然这些方法可能并不能完全覆盖所有的问题,但是这样的一些方法也基本可以处理绝大多数遇到的问题.下面的一些问题基本直接来源于公司的面试笔试题目, ...
- 大数据算法->推荐系统常用算法之基于内容的推荐系统算法
港真,自己一直非常希望做算法工程师,所以自己现在开始对现在常用的大数据算法进行不断地学习,今天了解到的算法,就是我们生活中无处不在的推荐系统算法. 其实,向别人推荐商品是一个很常见的现象,比如我用了一 ...
- 大数据list去重
MaxList模块主要是对Java集合大数据去重的相关介绍. 背景: 最近在项目中遇到了List集合中的数据要去重,大概一个2500万的数据,开始存储在List中,需要跟一个2万的List去去重. 直 ...
- List<Map>中根据map的同一指标项数据——去重代码
先看网络上,博客经常出现的错误代码: for(ABatchAddCheckVO aBatchAddCheckVO : addList){ dto.put("aac001",aBat ...
随机推荐
- AJPFX讲解java单例模式
单例设计模式概述: 单例模式就是要确保类在内存中只有一个对象,该实例必须自动创建,并且对外提供单例模式有以下特点: 1.单例类只能有一个实例. 2.单例类必须自己自己创建自己的唯一实例. 3 ...
- colormap画出的图不是彩色问题
针对matlab2017渲染出的彩色图是黑白的问题. t=labels; t(tstSet(:,end-))=Relabels; t=reshape(t,,); t=t'; figure imshow ...
- install nginx error
the error info : the HTTP gzip module requires the zlib library.You can either disable the module by ...
- 简单探讨弹性布局flex
css 弹性布局: 盒子模型: box-sizing属性1.content-box 正常的普通的盒子模型用padding和border会使盒子变大:(向外扩张)2.border-box 盒子模型,pa ...
- python_函数的可变参数
def test(*args,**kwargs): print(args) print(kwargs) test(1,2,3,x=1,y=2) 运行结果: *args称为positional argu ...
- Swift3命名空间的实现
最近在看一些Swift开源库的时候,发现了一些优秀的开源库都使用了命名空间,例如Kingfisher这个开源库中,就针对UIImage,UIImageView,UIButton做了命名空间的扩展.通过 ...
- JAVA——不简单的fianl关键字
protected用来修饰 域,代表域的访问权限是:包权限 或者 不同包,但是是子类 : final 修饰常量只要是该常量代入的计算式,在编译时期,就会被执行计算,以减轻运行时的负担.(只对基本数据类 ...
- MySql(一)mysql服务的基本操作及环境配置
MySQL服务的启动开始–>计算机–>右键选择管理–>双击打开服务和应用程序–>双击服务–>找到MySQL的服务名称(我的是MySQL56),右键选择启动即可 通过命令行 ...
- html 零散问题
1.iconfont的使用 https://www.cnblogs.com/yujihang/p/6706056.html 2.阴影效果比较 box-shadow:0 0 6px #000 inset ...
- autofs - automounter maps的格式
描述(DESCRIPTION) automounter maps 是一系列非主映射文件或者是NIS映射(NIS maps),它们被 automounter 的主映射文件(master map)具体调用 ...