Downloads: dump_Judy.patch

File dump_Judy.patch, 4.8 KB (added by admin, 9 years ago)
  • Makefile.config

    diff --git a/Makefile.config b/Makefile.config
    index 0d4c90d..be9c42c 100644
    a b  
    1 #JUDY_INC=-I/opt/local/include
    2 #JUDY_LIB=-L/opt/local/lib
    3 
    41PREFIX=/usr/local
    52INSTALL_BIN=$(PREFIX)/bin
    6 INSTALL_DATA=$(PREFIX)/share
    7  No newline at end of file
     3INSTALL_DATA=$(PREFIX)/share
  • src/Makefile

    diff --git a/src/Makefile b/src/Makefile
    index 2426051..72f5009 100644
    a b  
    11include ../Makefile.config
    22
    3 CC=gcc
    4 CFLAGS=-Wall -O3 $(JUDY_INC)
    5 LIBS=$(JUDY_LIB) -lJudy
     3CC=g++
     4CFLAGS=-Wall -O3
    65
    76OBJS=version.o buzhash.o
    87TARGETS=hashgen hashdup onion
  • src/onion.c

    diff --git a/src/onion.c b/src/onion.c
    index 08dca9a..1dc1327 100644
    a b  
    1313#include <unistd.h>
    1414#include <sys/time.h>
    1515#include <sys/resource.h>
    16 #include <Judy.h>
    1716#include "buzhash.h"
    1817#include "version.h"
    1918
     19#if defined __GNUC__ || defined __APPLE__
     20#include <ext/hash_map>
     21namespace std { using namespace __gnu_cxx; }
     22#else
     23#include <hash_map>
     24#endif
     25using namespace std;
     26typedef hash_map<uint64_t,bool> ngrhash;
     27
    2028#define BITMASK_HIGH63 0xfffffffffffffffeul
    2129
    2230#define NGRAM_SIZE 7
    int main(int argc, char **argv) {  
    216224    buzhash_buffer_t bh_buffer;
    217225    buzhash_init_buffer(&bh_buffer, Ngram_size);
    218226
    219     // judy - for global duplicates
    220     int judy_rc;
    221     Pvoid_t judy = (Pvoid_t) NULL;
    222 
    223     // ljudy - for local (document level) duplicates
    224     Pvoid_t ljudy = (Pvoid_t) NULL;
     227    ngrhash global, local;
    225228
    226229    // read hashes of duplicate n-grams if available
    227230    int have_dupl_ngrams = 0;
    int main(int argc, char **argv) {  
    244247            hash_t masked_hash = hash & hash_bitmask;
    245248            // store only the 63 most significant bits of the hash;
    246249            // reserve the last bit as a flag (seen / unseen)
    247             J1S(judy_rc, judy, masked_hash & BITMASK_HIGH63);
     250            global[masked_hash & BITMASK_HIGH63] = true;
    248251
    249252            // print progress information
    250253            if (!Quiet && bytes_read % (10000000 * sizeof(hash)) == 0) {
    int main(int argc, char **argv) {  
    331334        int doc_i;
    332335        for (doc_i=0; doc_i<doc_count-1; doc_i++) {
    333336            buzhash_clear_buffer(&bh_buffer);
    334             J1FA(judy_rc, ljudy);
     337            local.clear();
    335338            // for all paragraphs in the document
    336339            int par_i;
    337340            for (par_i=docs[doc_i]; par_i<docs[doc_i+1]; par_i++) {
    int main(int argc, char **argv) {  
    359362                    hash_t masked_hash = hash & hash_bitmask;
    360363                    if (!buzhash_is_full_buffer(&bh_buffer))
    361364                        continue;
    362                     J1T(judy_rc, ljudy, hash);
    363                     if (!judy_rc) {
     365                    ngrhash::const_iterator it = local.find (hash);
     366                    if (it == local.end()) {
    364367                        if (have_dupl_ngrams) {
    365368                            // test with the last bit set to 1
    366369                            // (check against already seen duplicate ngrams)
    367                             J1T(judy_rc, judy, masked_hash | 1);
     370                            it = global.find (masked_hash | 1);
    368371                        }
    369372                        else {
    370                             J1T(judy_rc, judy, masked_hash);
     373                            it = global.find (masked_hash);
    371374                        }
    372375                    }
    373                     if (judy_rc) {
     376                    if (it != global.end()) {
    374377                        bad_tokens+= Ngram_size - prev_bad_tokens;
    375378                        prev_bad_tokens = Ngram_size;
    376379                    }
    377                     J1S(judy_rc, ljudy, hash);
     380                    local[hash] = true;
    378381                }
    379382
    380383                // remember the length of the paragraph
    int main(int argc, char **argv) {  
    455458                            // stored hash to 1 if we have seen the matching
    456459                            // duplicate n-gram to indicate it has been seen.
    457460                            // Unique n-grams are ignored.
    458                             J1U(judy_rc, judy, masked_hash & BITMASK_HIGH63);
    459                             if (judy_rc)
    460                                 J1S(judy_rc, judy, masked_hash | 1);
     461                            if (global.erase (masked_hash & BITMASK_HIGH63))
     462                                global[masked_hash | 1] = true;
    461463                        }
    462464                        else {
    463465                            // otherwise we have to store hashes of all n-grams
    464                             J1S(judy_rc, judy, masked_hash);
     466                            global[masked_hash] = true;
    465467                        }
    466468                    }
    467469                }
    int main(int argc, char **argv) {  
    502504
    503505    return 0;
    504506}
     507
     508// vim: ts=4 sw=4 sta et sts=4 si cindent tw=80: