是否有任何概率数据结构可以给出假阴性而不是误报?

pat*_*rit 4 hash probability bloom-filter data-structures

我需要一个节省空间的概率数据结构来存储我已经计算过的值.对我来说,计算是便宜的但是空间不是 - 所以如果这个数据结构返回假阴性,我可以偶尔重做一些工作,但误报是不可接受的.所以我正在寻找的是与布隆过滤器相反的东西.

Sha*_*lik 7

对于假阴性,您可以使用有损哈希表或LRUCache.它是一种具有快速O(1)查找的数据结构,只会产生漏报.如果你问"我是否运行测试X",它会告诉你"是的,你肯定有",或"我不记得了".

伪代码:

setup_test_table():
    create test_table( some large number of entries )
    clear each entry( test_table, NEVER )
    return test_table

has_test_been_run_before( new_test_details, test_table ):
    index = hash( test_details , test_table.length )
    old_details = test_table[index].detail
    // unconditionally overwrite old details with new details, LRU fashion.
    // perhaps some other collision resolution technique might be better.
    test_table[index].details = new_test_details
    if ( old_details === test_details ) return YES
    else if ( old_details === NEVER ) return NEVER
    else return PERHAPS    

main()
    test_table = setup_test_table();
    loop
        test_details = generate_random_test()
        status = has_test_been_run_before( test_details, test_table )
        case status of
           YES: do nothing;
           NEVER: run test (test_details);
           PERHAPS: if( rand()&1 ) run test (test_details);
    next loop
end.
Run Code Online (Sandbox Code Playgroud)

类似地布隆过滤器用于误报