Example #1
0
int Board::next(Direction dir, int current)
{
    if(nextRow(dir, current)>=0)
        return -1;

    switch(dir)
    {
    case up:
        if(current > 0)
            return current - 4;
        else
            return -1;
    case down:
        if(current < 15)
            return current + 4;
        else
            return -1;
    case left:
        if(current < 15)
            return current + 1;
        else
            return -1;
    case right:
        if(current > 0)
            return current - 1;
        else
            return -1;
    }
    return -1;
}
Example #2
0
static void checkTblOrder(struct sqlConnection *conn,
                          char *tbl, char *chromFld, char *startFld)
/* check sorting of a positional table */
{
verbose(2, "checking %s.%s\n", sqlGetDatabase(conn), tbl);
char prevChrom[256], *chrom;
prevChrom[0] = '\0';
int prevStart = 0, start;
off_t irow = 0;

char query[512];
sqlSafef(query, sizeof(query), "SELECT %s,%s FROM %s", chromFld, startFld, tbl);
struct sqlResult *sr = sqlGetResult(conn, query);
while (nextRow(sr, &chrom, &start))
    {
    if (!sameString(chrom, prevChrom))
        {
        safecpy(prevChrom, sizeof(prevChrom), chrom);
        prevStart = start;
        }
    else
        {
        if (start < prevStart)
            errAbort("table %s.%s not sorted starting at row %lld: %s:%d",
                     sqlGetDatabase(conn), tbl, (long long)irow, chrom, start);
        prevStart = start;
        }
    irow++;
    }
sqlFreeResult(&sr);
}
Example #3
0
void Board::move(Direction dir)
{
    // simple move
    int currLoc;
    int nextLoc = initPos(dir);

    for(int i = 0; i < 4; ++i)
    {
        bool swapped;
        int initNext = nextLoc;
        do
        {
            swapped = false;
            for(int j = 0; j < 3; ++j)
            {
                currLoc = nextLoc;
                nextLoc = next(dir, nextLoc);
                if(m_state[nextLoc] == 0 && m_state[currLoc] != 0)
                {
                    swap(currLoc, nextLoc);
                    swapped = true;
                }
            }
            nextLoc = initNext;
        }
        while(swapped);
        nextLoc = nextRow(dir, next(dir, currLoc));
    }
}
Example #4
0
 const void *nextRowGENoCatch(const void *seek, unsigned numFields, bool &wasCompleteMatch, const SmartStepExtra &stepExtra)
 {
     ActivityTimer t(totalCycles, timeActivities, NULL);
     while (!abortSoon)
     {
         OwnedConstThorRow ret = input->nextRowGE(seek, numFields, wasCompleteMatch, stepExtra);
         if (!ret)
         {
             abortSoon = true;
             return NULL;
         }
         if (!wasCompleteMatch)
         {
             anyThisGroup = false; // RKC->GH - is this right??
             return ret.getClear();
         }
         if (helper->isValid(ret))
         {
             anyThisGroup = true;
             dataLinkIncrement();
             return ret.getClear();
         }
         if (!stepExtra.returnMismatches())
             return nextRow();
         if (stepCompare->docompare(ret, seek, numFields) != 0)
         {
             wasCompleteMatch = false;
             anyThisGroup = false; // WHY?
             return ret.getClear();
         }
     }
     return NULL;
 }
Example #5
0
ItemTreePtr Solver::compute()
{
	// Currently this is only called at the root of the decomposition.
	assert(decomposition.isRoot());
	nextRow();
	ItemTreePtr result = claspCallback->finalize(false, false);
	app.getPrinter().solverInvocationResult(decomposition, result.get());
	return result;
}
Example #6
0
void Board::collapse(Direction dir)
{
    dir = reversePosition(dir);
    int currLoc;
    int nextLoc = initPos(dir);

    for(int i = 0; i < 4; ++i)
    {
        for(int j = 0; j < 3; ++j)
        {
            currLoc = nextLoc;
            nextLoc = next(dir, nextLoc);
            if((m_state[nextLoc] != 0) && (m_state[currLoc] == m_state[nextLoc]))
            {
                m_state[nextLoc] *= 2;
                m_state[currLoc] = 0;
            }
        }
        nextLoc = nextRow(dir, next(dir, currLoc));
    }
}
Example #7
0
void *backpopulate_phash_inner( void *u) {

  pthread_t thread[MAX_THREADS];
  pthread_attr_t attr;
  int thread_pointer = 0;
  int avail_processors = 1;

  // We may have 16 processing cors, but only use what we need
  avail_processors = get_nprocs() - 1;
  if( avail_processors > MAX_THREADS ) {
    avail_processors = MAX_THREADS;
  }

  // initialise threading
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

  for( thread_pointer = 0; thread_pointer < MAX_THREADS; thread_pointer++ ) {
    pthread_create( &thread[ thread_pointer], &attr, stub, (void *)NULL );
  }
  thread_pointer = 0;

  // What tasks do we need to do
  struct simpleLinkedList *rSet;
  char *sql = o_strdup("SELECT filetype, docid FROM docs WHERE image_phash = 0");
  rSet = runquery_db(sql, NULL);
  if( rSet != NULL ) {
    do {

      // Queue up the next task
      int docid = atoi( readData_db(rSet, "docid") );
      char *docfilename;
      if( ( 0 == strcmp("2", readData_db(rSet, "filetype") ) ) 
      || ( 0 == strcmp("4", readData_db(rSet, "filetype") ) ) ) {
        docfilename = o_printf("%s/scans/%d_1.jpg", BASE_DIR, docid);
      }
      else {
        docfilename = o_printf("%s/scans/%d_thumb.jpg", BASE_DIR, docid);
      }

      // Wait for an available worker
      while( thread_active[thread_pointer] == 1 ) {
        thread_pointer++;
        if( thread_pointer > avail_processors ) {
          thread_pointer = 0;
        }
        usleep(200);
      }

      // Wait for it to join back first
      pthread_join( thread[ thread_pointer ], NULL);

      // Give instructions to the next worker
      struct process_phash *data = malloc( sizeof( struct process_phash ) );
      data->filename = docfilename;
      data->docid = docid;
      data->thread_id = thread_pointer;
      thread_active[thread_pointer] = 1;
      pthread_create( &thread[ thread_pointer], &attr, process_doc, (void *)data );

    } while ( nextRow( rSet ) );
    free_recordset( rSet );
  }
  free(sql);

  // Wait for everything t ofinish
  for( thread_pointer = 0; thread_pointer < MAX_THREADS; thread_pointer++ ) {
    pthread_join( thread[ thread_pointer ], NULL);
  }

  // Set the config flag, so we don't try this again.
  o_log(INFORMATION, "Marking that the backpopulation of pHash is: complete" );
  sql = o_strdup("UPDATE config SET config_value = 'complete' WHERE config_option = 'backpopulate_phash'");
  runUpdate_db(sql, NULL);
  free(sql);

  return NULL;
}
void RowBitmapLineSegmentFinder::nextRow(uint8_t rowIndex, uint8_t bitmapHigh, uint8_t bitmapLow, LineSegment previousLineSegment) {
  firstLineSegment = previousLineSegment;
  nextRow(rowIndex, bitmapHigh, bitmapLow);
}
Example #9
0
int setup (char *configFile) {

  struct simpleLinkedList *rSet;
  char *location, *conf, *sql;

  printf("entering setup\n");

  // Defaults
  VERBOSITY = DEBUGM;
  LOG_DIR = o_printf("%s/log/opendias", VAR_DIR);

  // Get 'DB' location
  if (configFile != NULL) {
    conf = o_strdup(configFile);
  }
  else {
    conf = o_printf("%s/opendias/opendias.conf", ETC_DIR);
    if( 0 != access(conf, F_OK) ) {
      o_log(INFORMATION, "Config not in GNU location: %s. Attempting system config dir /etc/opendias/opendias.conf", conf);
      free(conf);
      conf = o_strdup("/etc/opendias/opendias.conf");
    }
  }

  o_log(INFORMATION, "|Using config file: %s", conf);
  if( 0 == load_file_to_memory(conf, &location) ) {
    o_log(ERROR, "|Cannot find main config file: %s", conf);
    free(location);
    free(conf);
    return 1;
  }
  free(conf);

  chop(location);
  BASE_DIR = o_strdup(location);
  o_log(INFORMATION, "|Which says the database is at: %s", BASE_DIR);

  // Open (& maybe update) the database.
  if(connect_db (1)) { // 1 = create if required
    free(BASE_DIR);
    free(location);
    return 1;
  }
  free(location);

  o_log(INFORMATION, "|Current config is: ");
  sql = o_strdup("SELECT config_option, config_value FROM config");

  rSet = runquery_db(sql, NULL);
  if( rSet != NULL ) {
    do {
      char *config_option, *config_value;
      config_option = o_strdup(readData_db(rSet, "config_option"));
      config_value = o_strdup(readData_db(rSet, "config_value"));

      if ( config_option == NULL || config_value == NULL ) {
        printf("either option or value is NULL\n");
      } 
      else {
        //o_log(INFORMATION, "    %s = %s", config_option, config_value);
        //remark: the pipe in the message causes o_log i_o_log to crash
        //	caused by debug.c i_o_log by double use of vprintf
        o_log(INFORMATION, "|    %s = %s", config_option, config_value);
      }

      if( 0 == strcmp(config_option, "log_verbosity") ) {
        VERBOSITY = atoi(config_value);
      }

      free(config_option);
      free(config_value);
    } while ( nextRow( rSet ) );
  }
  free_recordset( rSet );
  free(sql);

  return 0;
}