Changeset 211

Show
Ignore:
Timestamp:
01/13/07 14:36:34 (1 year ago)
Author:
ug
Message:

Added signature search (\!GameList::sigsearch())

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/libkombilo/search.cpp

    r210 r211  
    514514    // printf("%d, %d, %d, %d, %d, %d, %d\n", f, newSizeX, newSizeY, newLeft, newRight, newTop, newBottom); 
    515515    char* newInitialPos = new char[pattern.sizeX*pattern.sizeY]; 
    516     unsigned i=0; 
     516    int i=0; 
    517517    for(i=0; i<pattern.sizeX; i++) { 
    518518      for(int j=0; j<pattern.sizeY; j++) { 
     
    35633563  if (currentList) delete currentList; 
    35643564  if (oldList) delete oldList; 
    3565   for(int i=0; i<20*boardsizes.size(); i++)  
     3565  for(unsigned int i=0; i<20*boardsizes.size(); i++)  
    35663566    if (algo_ps[i]) delete algo_ps[i]; 
    35673567  if (db) sqlite3_close(db); 
     
    37573757} 
    37583758 
     3759void GameList::sigsearch(char* sig) throw(DBError) { 
     3760  if (start_sorted() == 0) {  
     3761    string query = "select id from algo_signature_19 where signature = ? order by id"; 
     3762    // int rc = sqlite3_exec(db, query.c_str(), sigs_callback, this, 0); 
     3763    sqlite3_stmt *ppStmt=0; 
     3764    int rc = sqlite3_prepare(db, query.c_str(), -1, &ppStmt, 0); 
     3765    if (rc != SQLITE_OK || ppStmt==0) throw DBError(); 
     3766    rc = sqlite3_bind_blob(ppStmt, 1, sig, 12, SQLITE_TRANSIENT); 
     3767    if (rc != SQLITE_OK || ppStmt==0) throw DBError(); 
     3768    do { 
     3769      rc = sqlite3_step(ppStmt); 
     3770      if (rc != SQLITE_DONE && rc != SQLITE_ROW) throw DBError(); 
     3771      if (rc == SQLITE_ROW) { 
     3772        makeIndexHit(sqlite3_column_int(ppStmt, 0), 0); 
     3773      } 
     3774    } while (rc == SQLITE_ROW); 
     3775    rc = sqlite3_finalize(ppStmt); 
     3776    if (rc != SQLITE_OK) throw DBError(); 
     3777 
     3778    end_sorted(); 
     3779  } 
     3780} 
     3781 
    37593782int gis_callback(void *gl, int argc, char **argv, char **azColName) { 
    37603783  if (!argc) return 1; 
     
    38533876} 
    38543877 
    3855 string GameList::getSGF(int i) throw(DBError) { 
    3856   if (!p_op->sgfInDB) return ""; 
    3857   return getCurrentProperty(i, "sgf"); 
    3858 } 
    3859  
    38603878int getpropcallback(void *s, int argc, char **argv, char **azColName) { 
    38613879  char** prop = (char**)s; 
     
    38653883  } 
    38663884  return 0; 
     3885} 
     3886 
     3887string GameList::getSignature(int i) throw(DBError) { 
     3888  if (i < 0 || i >= (int)currentList->size()) { 
     3889    // printf("index out of range\n"); 
     3890    return ""; 
     3891  } 
     3892  int index = (*all)[(*currentList)[i].second]->id; 
     3893  // int rc = sqlite3_open(dbname, &db);  
     3894  // if (rc) { 
     3895  //   sqlite3_close(db); 
     3896  //   db = 0; 
     3897  //   throw DBError(); 
     3898  // } 
     3899  char* prop = 0; 
     3900  char sql[200]; 
     3901  sprintf(sql, "select signature from algo_signature_19 where id = %d;", index); 
     3902  // printf("%s\n", sql); 
     3903  int rc = sqlite3_exec(db, sql, getpropcallback, &prop, 0); 
     3904  if (rc != SQLITE_OK) throw DBError(); 
     3905  // sqlite3_close(db); 
     3906  // db = 0; 
     3907 
     3908  if (!prop) return ""; 
     3909  string prop_str(prop); 
     3910  delete [] prop; 
     3911  return prop_str; 
     3912} 
     3913 
     3914string GameList::getSGF(int i) throw(DBError) { 
     3915  if (!p_op->sgfInDB) return ""; 
     3916  return getCurrentProperty(i, "sgf"); 
    38673917} 
    38683918 
  • 06/libkombilo/search.h

    r208 r211  
    602602    Continuation lookupContinuation(char x, char y); 
    603603 
     604    // ------- signature search --------------------------------------------------- 
     605    void sigsearch(char* sig) throw(DBError); 
     606    std::string getSignature(int i) throw(DBError); 
     607 
    604608    // ------- game info search --------------------------------------------------- 
    605609    void gisearch(char* sql, int complete=0) throw(DBError); 
  • 06/libkombilo/testsearch.py

    r206 r211  
    6262    print 'Player %d: %s' % (i, gl.plEntry(i)) 
    6363 
     64gl.reset() 
     65gl.sigsearch('cfcgjbbeckjc') 
     66print gl.size(), 'games with signature cfcgjbbeckjc.' 
     67gl.sigsearch('aaaaaaaaaaaa') 
     68print gl.size(), 'games with signature aaaaaaaaaaaa.' 
     69gl.reset() 
     70gl.sigsearch('dfcnfmepgkjo') 
     71print gl.size(), 'games with signature dfcnfmepgkjo:' 
     72print gl.currentEntryAsString(0) 
     73print 'signature of game 0: ', gl.getSignature(0) 
     74 
     75