`
ansjsun
  • 浏览: 202062 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

BitMap 用于查重..只能查数字

阅读更多
package ansj.sun.util;
public class BitMap {

	private static final byte MAX = 127;

	public static void main(String[] args) throws InterruptedException {
		int m = 1578015112 ;
		
		BitMap hm = new BitMap() ;
		
		hm.add(m) ;
		
		System.out.println(hm.contains(m));
	}

	public BitMap() {
		bytes = new byte[12500000];
	}

	public BitMap(int size) {
		bytes = new byte[size];
	}

	private byte[] bytes = null;

	public void add(int i) {
		int r = i / 8;
		int c = i % 8;
		bytes[r] = (byte) (bytes[r] | (1 << c));
	}

	public boolean contains(int i) {
		int r = i / 8;
		int c = i % 8;
		if (((byte) ((bytes[r] >>> c)) & 1) == 1) {
			return true;
		}
		return false;
	}

	public void remove(int i) {
		int r = i / 8;
		int c = i % 8;
		bytes[r] = (byte) (bytes[r] & (((1 << (c + 1)) - 1) ^ MAX));
	}

}
分享到:
评论
3 楼 ansjsun 2012-01-06  
chenyinle 写道
当整型数值小于1亿时,你的算法才有用,大于一亿的话,你的byte数组不够用了

 public BitMap() {   
        bytes = new byte[12500000];   
   } 


12500000  * 8 = 100000000  ;
你修改byte数组的初始大小就可以...
我试过50亿..其实只要内存储足够大 ....多大都不是问题..这只是一种压缩策略....
不是算法..就是个小技巧
2 楼 chenyinle 2012-01-06  
当整型数值小于1亿时,你的算法才有用,大于一亿的话,你的byte数组不够用了
1 楼 huqilong 2011-09-20  
呵呵,学习了.

相关推荐

    RoaringBitmap-0.7.45-API文档-中英对照版.zip

    赠送jar包:RoaringBitmap-0.7.45.jar; 赠送原API文档:RoaringBitmap-0.7.45-javadoc.jar; 赠送源代码:RoaringBitmap-0.7.45-sources.jar; 赠送Maven依赖信息文件:RoaringBitmap-0.7.45.pom; 包含翻译后的API...

    RoaringBitmap-0.7.45-API文档-中文版.zip

    赠送jar包:RoaringBitmap-0.7.45.jar; 赠送原API文档:RoaringBitmap-0.7.45-javadoc.jar; 赠送源代码:RoaringBitmap-0.7.45-sources.jar; 赠送Maven依赖信息文件:RoaringBitmap-0.7.45.pom; 包含翻译后的API...

    生成字体图片工具Bitmap Font Builder.exe

    Bitmap Font Builder.exe生成字体图片工具Bitmap Font Builder.exe

    绘制用纹理填充的图形,C#源代码Bitmap bitmap = new Bitmap("..\\..\\test.jpg");

    绘制用纹理填充的图形,C#源代码Bitmap bitmap = new ... e.Graphics.DrawImage(bitmap, 0, 0, bitmap.Width, bitmap.Height); e.Graphics.DrawEllipse(texturedPen, 100, 20, 200, 100); VisualStudio2008创建

    Bitmap_transform.rar_Bitmap Transform_bitmap

    在C#中,`System.Drawing.Bitmap`类是用于创建和操作位图的主要类。你可以通过从文件路径、流或者另一个图像创建Bitmap对象。一旦有了Bitmap对象,就可以访问其像素,执行各种操作。 1. **从数组到Bitmap**: 一个二...

    Image textImage = new Bitmap("..\\..\\Texture.ICO");

    Image textImage = new Bitmap("..\\..\\Texture.ICO"); TextureBrush textTextureBrush = new TextureBrush(textImage); Font myFont = new Font("SansSerif", 50); e.Graphics.DrawString("Hello gouyue", ...

    VC.bitmap.form.design.code.rar_VC 窗体设计_Vc

    标题"VC.bitmap.form.design.code.rar_VC 窗体设计_Vc"表明这个压缩包包含了关于如何在VC++中设计含有位图的窗体的相关代码。描述中的"VC 位图窗体设计经典代码"暗示了这是一些经典的实现方法,可能是经过实践验证的...

    旋转、反射和扭曲图像程序(C#源代码编写)Image image = new Bitmap("..\\..\\test.bmp");

    旋转、反射和扭曲图像程序(C#源代码编写)Image image = new Bitmap("..\\..\\test.bmp"); e.Graphics.DrawImage(image, 200, 200, 300, 300); Point[] destinationPoints = { new Point(0, 20), ...

    androidbitmap的用法.pdf

    最后,使用`Bitmap.createBitmap()`创建一个新的Bitmap,这个新的Bitmap就是按照指定比例缩放后的结果。 在实际开发中,需要注意Bitmap的内存管理。由于Bitmap占用大量内存,不恰当的使用可能导致内存溢出。因此,...

    bitmap-BMP.rar_BITMAP bmp_bmp类

    bitmap.LoadImage(_T("path_to_your_bitmap.bmp"), LR_LOADFROMFILE); ``` 显示BMP位图: MFC中的CView类通常用于显示文档内容,我们可以重写它的`OnDraw`方法来绘制位图。首先,确保你的视图类继承自`CView`,...

    本示例绘制位图,分两种方式1. 绘制Bitmap对象2.使用Drawable.draw方法绘制位图

    本示例 演示绘制位图,分两种方式 1. 绘制Bitmap对象 2.使用Drawable.draw方法绘制位图 详情请参见 http://blog.csdn.net/aduovip/article/details/6722949

    Android下利用Bitmap切割图片

    Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); // 创建Canvas对象,绑定到新的Bitmap Canvas canvas = new Canvas(canvasBitmap); // 绘制裁剪后的Bitmap canvas.draw...

    C#中bitmap、stream、byte类型转换实例

    bitmap.Save(memoryStream, ImageFormat.Jpeg); // 将Bitmap保存到MemoryStream ``` ### Stream到byte[]转换 MemoryStream是一个实现了Stream接口的类,它可以直接访问其内部的字节数组。我们可以使用ToArray()...

    处理bitmap内存溢出问题

    这可以通过设置`inJustDecodeBounds`属性为`true`并调用`BitmapFactory.decodeFile()`来实现,此时不会创建实际的`Bitmap`对象,但会填充`Options`对象中的`outWidth`和`outHeight`属性,用于计算合适的`...

    winform下Bitmap转wpf下ImageSource

    bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp); byte[] bitmapBytes = memoryStream.ToArray(); } ``` 2. **字节数组到WPF的BitmapSource**:接着,使用`System.Windows.Media.Imaging....

    简析Bitmap文件格式.rar_bitmap_blanket477

    Bitmap文件格式,通常被称作位图或像素图,是一种广泛使用的图像文件格式,尤其在数字图像处理领域中占据重要地位。"Bitmap Blanket477"可能是指一个特定的Bitmap图像实例或处理方法,但具体含义需要更多上下文来...

    bitmap_progress.zip_C++进度条背景_bitmap_progress_图形_进度条

    4. **Bitmap(位图)**:Bitmap是Windows操作系统中常见的图像格式,通常用于存储像素数据。在本案例中,背景图形可能是位图,通过编程方式加载到进度条组件上。 5. **关于文件**: - **AboutDlg.h/cpp**:通常...

    Activity跳转时传递Bitmap对象

    bitmap = Bitmap.createBitmap(imageView.getWidth(), imageView.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); imageView.draw(canvas); // 将ImageView的内容绘制到Bitmap } ``...

    Android中把bitmap存成BMP格式图片的方法

    首先,Android SDK提供了`Bitmap.compress()`方法来将Bitmap保存为JPEG或PNG格式,但不支持BMP。因此,我们需要自定义一个方法来处理BMP格式的转换。这个过程主要包括以下几个步骤: 1. **获取Bitmap的像素数据**:...

    bitmap_converter.rar_bitmap_bitmap convert_boot screen_converter

    Bitmap Converter for converting image files to kernel boot screen

Global site tag (gtag.js) - Google Analytics