UNPKG

allprofanity

Version:

A blazing-fast, multi-language profanity filter with advanced algorithms (Aho-Corasick, Bloom Filters) delivering 664% faster performance on large texts, intelligent leet-speak detection, and pattern-based context analysis

104 lines (103 loc) 2.48 kB
/** * Bloom Filter implementation for efficient set membership testing */ export declare class BloomFilter { private bitArray; private size; private hashCount; private itemCount; constructor(expectedItems: number, falsePositiveRate?: number); /** * Calculate optimal bit array size */ private calculateOptimalSize; /** * Calculate optimal number of hash functions */ private calculateOptimalHashCount; /** * Hash function 1 (FNV-1a variant) */ private hash1; /** * Hash function 2 (djb2 variant) */ private hash2; /** * Generate k hash values for an item using double hashing */ private getHashes; /** * Set a bit in the bit array */ private setBit; /** * Get a bit from the bit array */ private getBit; /** * Add an item to the bloom filter */ add(item: string): void; /** * Add multiple items to the bloom filter */ addAll(items: string[]): void; /** * Test if an item might be in the set */ mightContain(item: string): boolean; /** * Test multiple items at once */ mightContainAny(items: string[]): boolean; /** * Filter items that might be in the set */ filter(items: string[]): string[]; /** * Clear the bloom filter */ clear(): void; /** * Get current false positive probability */ getCurrentFalsePositiveRate(): number; /** * Get bloom filter statistics */ getStats(): { size: number; hashCount: number; itemCount: number; bitsSet: number; loadFactor: number; estimatedFalsePositiveRate: number; }; /** * Serialize bloom filter to JSON */ toJSON(): { size: number; hashCount: number; itemCount: number; bitArray: number[]; }; /** * Deserialize bloom filter from JSON */ static fromJSON(data: { size: number; hashCount: number; itemCount: number; bitArray: number[]; }): BloomFilter; /** * Union operation with another bloom filter */ union(other: BloomFilter): BloomFilter; /** * Intersection operation with another bloom filter */ intersect(other: BloomFilter): BloomFilter; }