<commit_before>#ifndef HASHEROBJ
#define HASHEROBJ

#include "header.h"
#include "iotools.h"
//#include "path_manager.hpp"
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <fstream>

using namespace std;
using namespace cv;


class HasherObject {
    
    public:
        // What should the parameters be here?
        HasherObject() {
            // set default values
            feature_dim = 4096;
            bit_num = 256;
            int_num = bit_num/32;
            // l2-norm features
            norm = true;
            // number of features to retrieve for reranking
            // would be overwritten based on ratio and data_num
            top_feature = 2000;
            // Use negative near_dup_th when not set.
            near_dup_th = -1.0;
            ratio = 0.001f;
            // number of features indexed
            data_num = 0;
            // initialize path manager
            pm.set_paths(norm, bit_num);
            // initialize timing
            t[0] = 0.0;
            reset_timings();
            // initialize output buffer to speed up writing out results
            outputfile.rdbuf()->pubsetbuf(buffer, length);
        };

        // What need to be freed/closed?
        ~HasherObject() {
            itq.release();
            W.release();
            mvec.release();
            top_feature_mat.release();
            postrank.clear();
            hamming.clear();
            // accum?
            // query_codes?
        };

        void reset_timings() {
            for (int _t=1; _t<8; _t++)
                t[_t] = 0.0; 
        }

        int initialize() {
            double t_start = get_wall_time();
            int status = read_update_files();
            if (status != 0)
                return status;
            fill_data_nums_accum();
            status = load_itq_model();
            if (status != 0)
                return status;
            status = load_hashcodes();
            if (status != 0)
                return status;
            double t_init = get_wall_time() - t_start;
            cout << "[initialize] Done in " << t_init << "s." << endl;
            return 0;
        };

        int read_update_files();


        // Load DB hashcodes from files listed in update_file
        int load_hashcodes();

        // Load ITQ model
        int load_itq_model();

        // io from disk
        Mat read_feats_from_disk(string filename);

        //Mat read_hashcodes_from_disk(string filename); 
        void set_query_feats_from_disk(string filename);
<commit_msg>Deal with cold start in hashing<commit_after>#ifndef HASHEROBJ
#define HASHEROBJ

#include "header.h"
#include "iotools.h"
//#include "path_manager.hpp"
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <fstream>

using namespace std;
using namespace cv;


class HasherObject {
    
    public:
        // What should the parameters be here?
        HasherObject() {
            // set default values
            feature_dim = 4096;
            bit_num = 256;
            int_num = bit_num/32;
            // l2-norm features
            norm = true;
            // number of features to retrieve for reranking
            // would be overwritten based on ratio and data_num
            top_feature = 2000;
            // Use negative near_dup_th when not set.
            near_dup_th = -1.0;
            ratio = 0.001f;
            // number of features indexed
            data_num = 0;
            // initialize path manager
            pm.set_paths(norm, bit_num);
            // initialize timing
            t[0] = 0.0;
            reset_timings();
            // initialize output buffer to speed up writing out results
            outputfile.rdbuf()->pubsetbuf(buffer, length);
        };

        // What need to be freed/closed?
        ~HasherObject() {
            itq.release();
            W.release();
            mvec.release();
            top_feature_mat.release();
            postrank.clear();
            hamming.clear();
            // accum?
            // query_codes?
        };

        void reset_timings() {
            for (int _t=1; _t<8; _t++)
                t[_t] = 0.0; 
        }

        int initialize() {
            double t_start = get_wall_time();
            int model_status = load_itq_model();
            if (model_status != 0)
                return model_status;
            int update_status = read_update_files();
            if (update_status != 0) {// there is no update.
                cout << "[initialize: WARNING] Could not find update file." << endl;
            } else {
                fill_data_nums_accum();
                int data_status = load_hashcodes();
                if (data_status != 0)
                    cout << "[initialize: WARNING] Could not read any data." << endl;
            }
            double t_init = get_wall_time() - t_start;
            cout << "[initialize] Done in " << t_init << "s." << endl;
            return 0;
        };

        int read_update_files();


        // Load DB hashcodes from files listed in update_file
        int load_hashcodes();

        // Load ITQ model
        int load_itq_model();

        // io from disk
        Mat read_feats_from_disk(string filename);

        //Mat read_hashcodes_from_disk(string filename); 
        void set_query_feats_from_disk(string filename);

{'fraction_non_alphanumeric': 0.09798432250839866, 'fraction_numerical': 0.012318029115341545, 'mean_word_length': 1.4925581395348837, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1879153', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1462, 'n_words': 410}