Changeset 239 for 06/libkombilo/search.h

Show
Ignore:
Timestamp:
03/09/07 16:38:11 (22 months ago)
Author:
ug
Message:

Handling of duplicates within GameList, also during process.
Better access to processing results.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 06/libkombilo/search.h

    r230 r239  
    201201    virtual void branchpoint_process(); 
    202202    virtual void endOfVariation_process(); 
    203     virtual void endgame_process(); 
     203    virtual void endgame_process(bool commit=true); 
    204204    virtual void finalize_process(); 
    205205    virtual int readDB(sqlite3* DB); 
     
    225225    void branchpoint_process(); 
    226226    void endOfVariation_process(); 
    227     void endgame_process() throw(DBError); 
     227    void endgame_process(bool commit=true) throw(DBError); 
    228228    void finalize_process(); 
    229229 
    230230    int counter; 
    231231    char* signature; 
     232    char* get_current_signature(); 
     233    std::vector<int> search_signature(char* sig); 
    232234  private: 
    233235    bool main_variation; 
     
    248250    void branchpoint_process(); 
    249251    void endOfVariation_process(); 
    250     void endgame_process() throw(DBError); 
     252    void endgame_process(bool commit=true) throw(DBError); 
    251253    void finalize_process(); 
    252254 
     
    256258    int readDB(sqlite3* DB); 
    257259    int search(PatternList& patternList, GameList& gl, SearchOptions& options); 
     260 
     261    bool equal(unsigned int id1, unsigned int id2); // id1, id2 refer to id's in the database! 
     262    bool equals_current(unsigned int id1); 
    258263}; 
    259264 
     
    317322    void branchpoint_process(); 
    318323    void endOfVariation_process(); 
    319     void endgame_process() throw(DBError); 
     324    void endgame_process(bool commit=true) throw(DBError); 
    320325    void finalize_process(); 
    321326    int readDB(sqlite3* DB); 
     
    329334}; 
    330335 
     336class HashFEntry { 
     337  public: 
     338    hashtype hashCode; 
     339    char* buf; 
     340    int length; 
     341 
     342    HashFEntry(hashtype HASHCODE, char* BUF, int LENGTH); 
     343    HashFEntry(const HashFEntry& hfe); 
     344    ~HashFEntry(); 
     345}; 
    331346 
    332347class HashhitF { // hashing hit for full board search 
     
    374389    void branchpoint_process(); 
    375390    void endOfVariation_process() throw(DBError); 
    376     void endgame_process() throw(DBError); 
     391    void endgame_process(bool commit=true) throw(DBError); 
    377392    void finalize_process(); 
    378393    int search(PatternList& patternList, GameList& gl, SearchOptions& options, sqlite3* db); 
    379394 
    380     int insert_hash(hashtype hashCode, ExtendedMoveNumber& mn, Move* continuation); 
    381395    hashtype compute_hashkey(Pattern& pattern); 
    382396 
     397    int maxNumStones; 
     398    int numStones; 
     399  private: 
    383400    hashtype currentHashCode; 
    384401    ExtendedMoveNumber* moveNumber; 
    385402    std::vector<std::pair<hashtype, ExtendedMoveNumber>* > *lfc; // hash code + move number, still looking for continuation 
    386403    std::stack<HashVarInfo>* branchpoints; 
    387     int maxNumStones; 
    388     int numStones; 
     404    int insert_hash(hashtype hashCode, ExtendedMoveNumber& mn, Move* continuation); 
     405    int insert_all_hashes(); 
     406    std::vector<HashFEntry> hash_vector; 
    389407}; 
    390408 
     
    439457    virtual void branchpoint_process(); 
    440458    virtual void endOfVariation_process(); 
    441     virtual void endgame_process(); 
     459    virtual void endgame_process(bool commit=true); 
    442460    virtual void finalize_process(); 
    443461    virtual int search(PatternList& patternList, GameList& gl, SearchOptions& options, sqlite3* db); 
    444462 
     463    virtual std::pair<hashtype,int> compute_hashkey(PatternList& pl, int CS); 
     464    static const hashtype hashCodes[]; 
     465    std::string dbnameext; 
     466    std::vector<HashInstance>* hi; 
     467    int maxNumStones; 
     468    std::vector<std::pair<hashtype, int> > hash_vector; 
    445469    virtual int insert_hash(hashtype hashCod, int pos); 
    446     virtual std::pair<hashtype,int> compute_hashkey(PatternList& pl, int CS); 
    447     std::vector<HashInstance>* hi; 
    448     std::string dbnameext; 
    449     int maxNumStones; 
    450  
    451     static const hashtype hashCodes[]; 
     470    int insert_all_hashes(); 
    452471}; 
    453472 
     
    569588    ~VarInfo(); 
    570589}; 
     590 
     591// process flags (used to determine the behavior for individual games - in contrast to 
     592// options which apply to the whole GameList and are given in ProcessOptions) 
     593const int CHECK_FOR_DUPLICATES = 1; // check for duplicates using the signature 
     594const int CHECK_FOR_DUPLICATES_STRICT = 2; // check for duplicates using the final position 
     595                                           // (if ALGO_FINAPOS is available) 
     596const int OMIT_DUPLICATES = 4; 
     597const int OMIT_GAMES_WITH_SGF_ERRORS = 8;  
     598const int INDEX_OUT_OF_RANGE = 16; 
     599 
     600// process return values 
     601// 0:   SGF error occurred when parsing the "tree structure" (i.e. before parsing the individual nodes) 
     602//      database was not changed 
     603// n>0: n games were processed, use process_results to access the individual results  
     604 
     605// flags used in process_results 
     606const int UNACCEPTABLE_BOARDSIZE = 1; // (database not changed)  
     607const int SGF_ERROR = 2; 
     608    // SGF error occurred when playing through the game  
     609    // (and the rest of the concerning variation was not used). 
     610    // Depending on OMIT_GAMES_WITH_SGF_ERRORS, everything before this node (and other variations,  
     611    // if any) was inserted, or the database was not changed. 
     612const int IS_DUPLICATE = 4; 
     613const int NOT_INSERTED_INTO_DB = 8; 
     614 
    571615 
    572616class GameList { 
     
    606650    // ------- processing SGF games (to populate the db) -------------------------- 
    607651    void start_processing(int PROCESSVARIATIONS=-1) throw(DBError); 
    608     int process(const char* sgf, const char* path, const char* fn, const char* DBTREE = 0) throw(SGFError,DBError); 
     652    int process(const char* sgf, const char* path, const char* fn, 
     653                const char* DBTREE = 0, int flags=0) throw(SGFError,DBError); 
     654    int process_results(unsigned int i=0); // result for i-th processed game in most recently processed SGF collection 
    609655    void finalize_processing() throw(DBError); 
    610656     
     657    // int remove_game(int index); // TODO 
     658    // int remove_all_current_games(); 
     659 
    611660    // ------- pattern search ----------------------------------------------------- 
    612661    // options is copied in the search method (if != 0), so the caller has to free the pointer 
     
    629678    void deleteTag(int tag, int i = -1) throw(DBError); 
    630679    std::vector<int> getTags(int i, int tag=0) throw(DBError); // note the order of arguments! 
     680     
     681    // ------- duplicates --------------------------------------------------------- 
     682    int find_duplicates(int bs, bool strict=false) throw(DBError); // return number of duplicate array 
     683    std::vector<int> retrieve_duplicates_VI(unsigned int i); 
     684    int* retrieve_duplicates_PI(unsigned int i); // same as above, but returns Pointer to Int  
     685                                                 // (an array terminated by -1) 
     686                                                 // The caller must free the pointer himself 
     687                                                 // (before calling find_duplicates again). 
    631688 
    632689    // ------- misc --------------------------------------------------------------- 
     
    659716    void makeIndexHit(int index, std::vector<Hit* > *hits); 
    660717    void setCurrentFromIndex(int index); 
     718    int get_current_index(int id, int* start); // returns the index in oldList of the game with game id "id"  
     719                                               // (if available, otherwise returns -1), 
     720                                               // use this between start_sorted and end_sorted 
     721    int get_current_index_CL(int id, int start=0); // returns the index in currentList of the game with game id "id"  
     722                                                   // (if available, otherwise returns -1), requires currentList to 
     723                                                   // be sorted wrt first component (see duplicates()) 
    661724 
    662725  private: 
     
    678741    std::vector<std::string> pl; // list of all players 
    679742    void readPlayersList() throw(DBError); 
     743    std::vector<std::vector<int> >* duplicates; 
     744    void insert_duplicate(int i1, int i2, std::vector<std::vector<int> >* dupl); 
     745    std::vector<int> process_results_vector; 
    680746}; 
    681747