Closed xtaylord closed 5 months ago
Could a feature be included to allow filters to be saved to a file or loaded from file? Thanks
Thank you for your issues.
BloomFilter aims to reduce the number of disk accesses to improve performance.
Redis are recommended for persistence.
Redis are recommended for persistence
I need to save bloom filters in the sql database and then import from the database. (Ex: blockchain logs usage etc)
public static class IBloomFilterExtensions
{
public static void GetBitArray(this IBloomFilter ins, out BitArray _hashBits1, out BitArray? _hashBits2)
{
_hashBits1 = (BitArray)typeof(FilterMemory).GetField("_hashBits1", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(ins);
_hashBits2 = (BitArray?)typeof(FilterMemory).GetField("_hashBits2", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(ins);
}
public static void SetBitArray(this IBloomFilter ins, BitArray bits1, BitArray? bits2)
{
GetBitArray(ins, out var _hashBits1, out var _hashBits2);
for (var i = 0; i < bits1.Length; i++)
_hashBits1[i] = bits1[i];
if (_hashBits2 == null || bits2 == null)
return;
for (var i = 0; i < bits2.Length; i++)
_hashBits2[i] = bits2[i];
}
}
public static class IBloomFilterExtensions { public static void GetBitArray(this IBloomFilter ins, out BitArray _hashBits1, out BitArray? _hashBits2) { _hashBits1 = (BitArray)typeof(FilterMemory).GetField("_hashBits1", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(ins); _hashBits2 = (BitArray?)typeof(FilterMemory).GetField("_hashBits2", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(ins); } public static void SetBitArray(this IBloomFilter ins, BitArray bits1, BitArray? bits2) { GetBitArray(ins, out var _hashBits1, out var _hashBits2); for (var i = 0; i < bits1.Length; i++) _hashBits1[i] = bits1[i]; if (_hashBits2 == null || bits2 == null) return; for (var i = 0; i < bits2.Length; i++) _hashBits2[i] = bits2[i]; } }
Do you want to expose BitArray for external use?
Could a feature be included to allow filters to be saved to a file or loaded from file? Thanks