FileDocCategorySizeDatePackage
BloomFilterAddRemove4Bit.javaAPI DocAzureus 3.0.3.42446Thu Feb 09 19:42:48 GMT 2006com.aelitis.azureus.core.util.bloom.impl

BloomFilterAddRemove4Bit

public class BloomFilterAddRemove4Bit extends BloomFilterImpl

Fields Summary
private byte[]
map
Constructors Summary
public BloomFilterAddRemove4Bit(int _max_entries)

		super( _max_entries );
		
		// 4 bits per entry
	
		map	= new byte[(getMaxEntries()+1)/2];
	
Methods Summary
protected intdecValue(int index)

		int	original_value = getValue( index );

		if ( original_value <= 0 ){
			
			return( 0 );
		}
				
		setValue( index, (byte)(original_value-1));
		
		return( original_value );
	
protected intgetValue(int index)

		byte	b = map[index/2];
				
		if ( index % 2 == 0 ){
			
			return(( b&0x0f ) & 0xff );
		}else{
			
			return(((b>>4)&0x0f) & 0xff );
		}
	
protected intincValue(int index)

		int	original_value = getValue( index );
		
		if ( original_value >= 15 ){
			
			return( 15 );
		}
				
		setValue( index, (byte)(original_value+1) );
		
		return( original_value );
	
private voidsetValue(int index, byte value)

		byte	b = map[index/2];
				
		if ( index % 2 == 0 ){
			
			b = (byte)((b&0xf0) | value );
			
		}else{
			
			b = (byte)((b&0x0f) | (value<<4)&0xf0 );
		}
		
		// System.out.println( "setValue[" + index + "]:" + Integer.toHexString( map[index/2]&0xff) + "->" + Integer.toHexString( b&0xff ));
		
		map[index/2] = b;
	
protected inttrimValue(int value)

		if ( value < 0 ){
			return( 0 );
		}else if ( value > 15 ){
			return( 15 );
		}else{
			return( value );
		}