Class BitArray
java.lang.Object
cloud.opencode.base.hash.bloom.BitArray
- All Implemented Interfaces:
Serializable
Bit array implementation for bloom filter
布隆过滤器的位数组实现
Provides an efficient bit array implementation with optional thread-safe operations using CAS.
提供高效的位数组实现,可选择使用CAS进行线程安全操作。
Features | 主要功能:
- Compact storage using long[] - 使用long[]的紧凑存储
- Optional thread-safe mode - 可选的线程安全模式
- Serialization support - 序列化支持
- Merge operations - 合并操作
Usage Examples | 使用示例:
// BitArray is used internally by BloomFilter
// BitArray由BloomFilter内部使用
BitArray bits = new BitArray(1024);
bits.set(42);
boolean isSet = bits.get(42); // true
- Since:
- JDK 25, opencode-base-hash V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongbitCount()Gets the number of set bits (population count) 获取已设置的位数(人口计数)longbitSize()Gets the number of bits 获取位数booleanclear(long index) Clears a bit 清除位voidclearAll()Clears all bits 清除所有位static BitArrayfromBytes(byte[] bytes) Creates a bit array from byte array 从字节数组创建位数组booleanget(long index) Gets a bit value 获取位值Performs OR operation with another bit array 与另一个位数组执行OR操作booleanset(long index) Sets a bit to true 将位设置为truebyte[]toBytes()Converts to byte array for serialization 转换为字节数组用于序列化
-
Constructor Details
-
BitArray
public BitArray(long bitSize) Creates a non-thread-safe bit array 创建非线程安全的位数组- Parameters:
bitSize- number of bits | 位数
-
BitArray
public BitArray(long bitSize, boolean threadSafe) Creates a bit array with optional thread safety 创建可选线程安全的位数组- Parameters:
bitSize- number of bits | 位数threadSafe- whether to be thread-safe | 是否线程安全
-
BitArray
public BitArray(long bitSize, long[] data) Creates a bit array from existing data 从现有数据创建位数组- Parameters:
bitSize- number of bits | 位数data- existing data | 现有数据
-
-
Method Details
-
set
public boolean set(long index) Sets a bit to true 将位设置为true- Parameters:
index- bit index | 位索引- Returns:
- true if the bit was changed | 如果位被更改返回true
-
get
public boolean get(long index) Gets a bit value 获取位值- Parameters:
index- bit index | 位索引- Returns:
- true if bit is set | 如果位已设置返回true
-
clear
public boolean clear(long index) Clears a bit 清除位- Parameters:
index- bit index | 位索引- Returns:
- true if the bit was changed | 如果位被更改返回true
-
bitSize
public long bitSize()Gets the number of bits 获取位数- Returns:
- bit count | 位数
-
bitCount
public long bitCount()Gets the number of set bits (population count) 获取已设置的位数(人口计数)- Returns:
- number of set bits | 已设置的位数
-
clearAll
public void clearAll()Clears all bits 清除所有位 -
or
-
toBytes
public byte[] toBytes()Converts to byte array for serialization 转换为字节数组用于序列化- Returns:
- byte array | 字节数组
-
fromBytes
Creates a bit array from byte array 从字节数组创建位数组- Parameters:
bytes- byte array | 字节数组- Returns:
- bit array | 位数组
- Throws:
IllegalArgumentException- if bytes are invalid | 如果字节无效则抛出异常
-