Search in sources :

Example 1 with ContentCache

use of com.biglybt.core.content.RelatedContentManager.ContentCache in project BiglyBT by BiglySoftware.

the class RelatedContentSearcher method testKeyBloom.

private void testKeyBloom() {
    if (true) {
        return;
    }
    System.out.println("test key bloom");
    try {
        Map<String, int[]> all_words = new HashMap<>();
        synchronized (manager.rcm_lock) {
            ContentCache cache = manager.loadRelatedContent();
            List<DownloadInfo> dht_infos = getDHTInfos(false);
            Iterator<DownloadInfo> it_dht = dht_infos.iterator();
            Iterator<DownloadInfo> it_transient = RelatedContentManager.transient_info_cache.values().iterator();
            Iterator<DownloadInfo> it_rc = cache.related_content.values().iterator();
            updateKeyBloom(cache);
            int i = 0;
            for (Iterator _it : new Iterator[] { it_transient, it_rc, it_dht }) {
                Iterator<DownloadInfo> it = (Iterator<DownloadInfo>) _it;
                while (it.hasNext()) {
                    DownloadInfo di = it.next();
                    List<String> words = getDHTWords(di);
                    for (String word : words) {
                        int[] x = all_words.get(word);
                        if (x == null) {
                            x = new int[3];
                            all_words.put(word, x);
                        }
                        x[i] = 1;
                    }
                }
                i++;
            }
        }
        BloomFilter bloom = getKeyBloom(true);
        int total = 0;
        int clashes = 0;
        int misses = 0;
        int match_fails = 0;
        Random random = new Random();
        for (Map.Entry<String, int[]> entry : all_words.entrySet()) {
            String word = entry.getKey();
            int[] source = entry.getValue();
            boolean r1 = bloom.contains(word.getBytes("UTF-8"));
            boolean r2 = bloom.contains((word + random.nextLong()).getBytes("UTF-8"));
            System.out.println(word + " -> " + r1 + "/" + r2);
            total++;
            if (r1 && r2) {
                clashes++;
            }
            if (!r1) {
                misses++;
            }
            List<RelatedContent> hits = matchContent(word, SEARCH_MIN_SEEDS_DEFAULT, SEARCH_MIN_LEECHERS_DEFAULT, true, false);
            if (hits.size() == 0) {
                hits = matchContent(word, SEARCH_MIN_SEEDS_DEFAULT, SEARCH_MIN_LEECHERS_DEFAULT, true, false);
                match_fails++;
            }
        }
        System.out.println("total=" + total + ", clash=" + clashes + ", miss=" + misses + ", fails=" + match_fails + ", bloom=" + bloom.getString());
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : ContentCache(com.biglybt.core.content.RelatedContentManager.ContentCache) BloomFilter(com.biglybt.core.util.bloom.BloomFilter) DownloadInfo(com.biglybt.core.content.RelatedContentManager.DownloadInfo)

Aggregations

ContentCache (com.biglybt.core.content.RelatedContentManager.ContentCache)1 DownloadInfo (com.biglybt.core.content.RelatedContentManager.DownloadInfo)1 BloomFilter (com.biglybt.core.util.bloom.BloomFilter)1