Пример #1
0
static void finish(cube21_conf *cp) 
{
  int j, s;
  int matches[12];
  switch(cp->state) {
    case CUBE21_PAUSE1:
      s = rnd01();
      find_matches(cp->pieces, matches, s);
      j = matches[0]-1;
      j = random()%j;
      j = matches[j+1];
      if(j==6 && rnd01()) j = -6;
      cp->state = CUBE21_ROT_BASE+s;
      cp->tmax = 30.0*abs(j);
      cp->fr[0] = cp->fr[1] = 0;
      cp->rface = s;
      cp->ramount = j;
      break;
    case CUBE21_ROT_TOP:
    case CUBE21_ROT_BOTTOM:
      rot_face(cp->pieces, cp->cind, s = cp->rface, cp->ramount);
      cp->fr[s] = 1;
      s ^= 1;
      if(!cp->fr[s] && rnd01()) {
        find_matches(cp->pieces, matches, s);
        j = matches[0]-1;
        j = random()%j;
        j = matches[j+1];
        if(j==6 && rnd01()) j = -6;
        cp->state = CUBE21_ROT_BASE+s;
        cp->tmax = 30.0*abs(j);
        cp->rface = s;
        cp->ramount = j;        
        break;
      } else {
        cp->state = CUBE21_PAUSE2;
        cp->tmax = twait;
        break;
      }
    case CUBE21_PAUSE2:
      s = rnd01();
      cp->ramount = -rnd01();       /* 0 or -1, only sign is significant in this case */
      cp->state = CUBE21_HALF_BASE+s;
      cp->tmax = 180.0;
      cp->rface = s;
      break;
    case CUBE21_HALF1:
    case CUBE21_HALF2:
      rot_halves(cp->pieces, cp->cind, cp->hf, cp->rface);
      cp->state = CUBE21_PAUSE1;
      cp->tmax = twait;
      break;
  }
  cp->t = 0;
}
Пример #2
0
Piece get_Piece(map<string, Piece> init_map, string type, char color, cell destination, char conflict) {

        Piece current_Piece;
        vector<Piece> candidates;
        if (type[0] == 'P') {
                candidates = get_valid_pawn_pieces(init_map, destination, color);
                if (conflict == 'n') {
                        candidates =  filterSlope(candidates, destination, type[0]);
                        if (candidates.size() > 1) {
                                current_Piece = filterDistance(candidates, destination, type[0]);
                        }
                        else if (candidates.size() == 1)
                                current_Piece = candidates[0];
                        return current_Piece;
                }
                else {
                        if (conflict >= '1' && conflict <= '8') {
                                int tmp = conflict - '1' + 1;
                                current_Piece = find_matches(candidates, tmp);
                        }
                        else
                                current_Piece = find_matches(candidates, conflict);
                        return current_Piece;
                }
        }
        else {
                candidates = get_valid_all_pieces(init_map, color, type[0]);
                if (conflict == 'n') {
                        candidates =  filterSlope(candidates, destination, type[0]);
                        if (candidates.size() > 1) {
                                current_Piece = filterDistance(candidates, destination, type[0]);
                        }
                        else if (candidates.size() == 1)
                                current_Piece = candidates[0];
                        return current_Piece;
                }
                else {
                        if (conflict >= '1' && conflict <= '8') {
                                int tmp = conflict - '1' + 1;
                                current_Piece = find_matches(candidates, tmp);
                        }
                        else
                                current_Piece = find_matches(candidates, conflict);
                        return current_Piece;
                }

        }

}
Пример #3
0
void menu_selector::populate()
{
	if (m_search[0] != 0)
	{
		find_matches(m_search);

		for (int curitem = 0; m_searchlist[curitem]; ++curitem)
			item_append(*m_searchlist[curitem], "", 0, (void *)m_searchlist[curitem]);
	}
	else
	{
		for (size_t index = 0, added = 0; index < m_str_items.size(); ++index)
			if (m_str_items[index] != "_skip_")
			{
				if (m_first_pass && m_selector == index)
					selected = added;

				added++;
				item_append(m_str_items[index], "", 0, (void *)&m_str_items[index]);
			}
	}

	item_append(menu_item_type::SEPARATOR);
	customtop = custombottom = ui().get_line_height() + 3.0f * UI_BOX_TB_BORDER;
	m_first_pass = false;
}
Пример #4
0
Файл: jool.c Проект: NICMx/Jool
static int __handle(char *iname, int argc, char **argv)
{
	struct cmd_option *nodes = &tree[0];
	struct cmd_option *node = NULL;
	int i;

	if (argc == 0)
		return more_args_expected(nodes);

	for (i = 0; i < argc; i++) {
		node = find_matches(nodes, argv[i]);
		if (!node)
			return unexpected_token(nodes, argv[i]);
		if (node->next)
			return ambiguous_token(node, argv[i]);

		if (node->handler) {
			return node->handler(iname, argc - i, &argv[i],
					node->args);
		}

		nodes = node->children;
	}

	return more_args_expected(node->children);
}
Пример #5
0
void ui_menu_selector::populate()
{
	if (m_search[0] != 0)
	{
		find_matches(m_search);

		for (int curitem = 0; m_searchlist[curitem]; ++curitem)
			item_append(m_searchlist[curitem]->c_str(), nullptr, 0, (void *)m_searchlist[curitem]);
	}
	else
	{
		for (size_t index = 0, added = 0; index < m_str_items.size(); ++index)
			if (m_str_items[index] != "_skip_")
			{
				if (m_first_pass && m_selector == index)
					selected = added;

				added++;
				item_append(m_str_items[index].c_str(), nullptr, 0, (void *)&m_str_items[index]);
			}
	}

	item_append(MENU_SEPARATOR_ITEM, nullptr, 0, nullptr);
	customtop = custombottom = machine().ui().get_line_height() + 3.0f * UI_BOX_TB_BORDER;
	m_first_pass = false;
}
void do_merge(row *rows, long nrows)
{
    long n = 0;
    
    for(n = 0; n < nrows; n++)
    {
        if(!(n % 5000) || n == nrows - 1)
            printf("%ld%% complete\n", n * 100 / (nrows - 1));
            
        assign_aclid(n, rows, nrows);
        find_matches(n, rows, nrows);
    }
}
Пример #7
0
SummaryDesc::SummaryDesc(Matcher* matcher, ssize_t length, ssize_t min_length,
                         int max_matches, int surround_len)
    : _matcher(matcher),
      _occ(matcher->OccurrenceList()),
      _match_results(matcher->OrderedMatchSet()),
      _length(length),
      _min_length(min_length),
      _remaining(length),
      _surround_len(surround_len),
      _est_len(0),
      _hit_len(0),
      _clist(),
      _plist(),
      _sumconf(),
      _max_matches(max_matches),
      _match_elems(),
      _document_length(matcher->DocumentSize()),
    _fulldoc()
{
    /* Check if the whole document fits within requested length and
     * process this
     */
    if (length + MIN_CONTINUATION*4 > (int)_document_length) {
        build_fulldoc_desc();
        return;
    }

    /* Adjust to sensible values */
    if (_surround_len < MIN_SURROUND_LEN)
        _surround_len = MIN_SURROUND_LEN;

    /* decide what amount of matches to use (stored in _clist) */
    _match_elems = find_matches();

    /* build highlight descriptor list */
    build_highlight_descs();

    /* Done with matches list. Clean up */
    _clist.clear();

    /* Spin through the resulting descriptor list and query term
     * occurrence list to
     *  1. identify (for highlight) accidental query term occurrences
     *     that are not part of the match
     *  2. Split descriptor list where new keyword matches are
     *     found. Extend if necessary due to partially included keywords.
     *  3. identify overlapping regions (possibly created by 2)
     */
    locate_accidential_matches();
}
Пример #8
0
static void randomize(cube21_conf *cp) 
{
  int i, j, s;
  int matches[12];
  for(i = 0; i<SHUFFLE; i++) {
    s = rnd01();
    find_matches(cp->pieces, matches, s);
    j = matches[0]-1;
    j = random()%j;
    j = matches[j+1];
    rot_face(cp->pieces, cp->cind, s, j);
    s = rnd01();
    rot_halves(cp->pieces, cp->cind, cp->hf, s);
  }
}
Пример #9
0
Action::Status CopyPatternAction::run() {
	owner->start(this);
	
	DBG_M_ACTIONS << " processing " << *this << "\n";
	status = Running;
    Value val;
    val = owner->getValue(property);
    std::vector<std::string>matches;
    rexp_info *info = create_pattern(pattern.c_str());
    find_matches(info, matches, val.asString().c_str());
    if (matches.size()) {
        owner->setValue(dest, matches[0]);
    }
    release_pattern(info);
	status = Complete;
	owner->stop(this);
	return status;
}
Пример #10
0
void test_case(const std::string& filename) {
    boost::program_options::variables_map vm;
    std::ifstream test_cases(filename);

    std::string line;
    while (std::getline(test_cases, line)) {
        // Ignore empty lines and comments
        if (line.size() < 4 || line.substr(0, 3) != "// ") {
            continue;
        }

        std::string statement = line.substr(3, std::string::npos);

        if (!std::getline(test_cases, line)) {
            std::cerr << "Unexpected end of test cases." << std::endl;
            exit(-1);
        }

        std::istringstream ss{line};
        ss.ignore(std::numeric_limits<std::streamsize>::max(), ' ');
        std::vector<int> matches;
        int match_line;

        while (ss >> match_line) {
            matches.push_back(match_line);
        }

        std::cout << "Testing: " << statement << std::endl;

        auto term = parse_search_string(statement, vm);
        auto found = find_matches(filename, term, vm);

        assert(found.size() == matches.size());
        for (std::size_t s = 0; s < found.size(); ++s) {
            assert(found[s].first.first == matches[s]);
        }

        std::cout << "  Passed" << std::endl;
    }
}
Пример #11
0
bool MatchingDynamicClusterer::add_clustering( Clustering &step_clustering )
{
	m_step += 1;
	/// First?
	if( m_step == 1 )
	{
		return bootstrap(step_clustering);
	}
	
	/// Otherwise, try to match all
	Clustering::iterator cit;
	Clustering::iterator cend = step_clustering.end();
	int step_cluster_index = 0;
	vector<DynamicCluster> fresh;
	PairVector matched_pairs;
	for( cit = step_clustering.begin() ; cit != cend; cit++, step_cluster_index++ )
	{
		vector<int> matches;
		find_matches( *cit, matches );
		// new community?
		if( matches.empty() )
		{
			DynamicCluster dc;
			dc.update( m_step, step_cluster_index, *cit );
			fresh.push_back(dc);
#ifdef DEBUG_MATCHING
			cout << "T" << m_step << ": Birth: Community M" << (m_dynamic.size()+fresh.size()) << " from C" << step_cluster_index+1 << endl;
#endif			
		}
		else
		{
			vector<int>::const_iterator iit;
			for( iit = matches.begin() ; iit != matches.end(); iit++ )
			{
				pair<int,int> p(step_cluster_index,(*iit));
				matched_pairs.push_back(p);
			}
		}
	}
	
	// Actually update existing dynamic communities now
	set<int> matched_dynamic;
	PairVector::const_iterator pit;
	for( pit = matched_pairs.begin(); pit != matched_pairs.end(); pit++ )
	{
		int step_cluster_index = (*pit).first;
		int dyn_cluster_index = (*pit).second;
		// already processed this dynamic cluster?
		if( matched_dynamic.count( dyn_cluster_index ) ) 
		{
			DynamicCluster dc( m_dynamic[dyn_cluster_index], m_step, step_cluster_index, step_clustering[step_cluster_index] );
			fresh.push_back(dc);
#ifdef DEBUG_MATCHING
			cout << "T" << m_step << ": Split: Matched C" << (step_cluster_index+1) << " to M" << (dyn_cluster_index+1) << ". Splitting to M" << (m_dynamic.size()+fresh.size()) <<  endl;
#endif
		}
		else
		{
#ifdef DEBUG_MATCHING
			cout << "T" << m_step << ": Continuation: Matched C" << (step_cluster_index+1) << " to M" << (dyn_cluster_index+1) << endl;
#endif
			m_dynamic[dyn_cluster_index].update( m_step, step_cluster_index, step_clustering[step_cluster_index] );
			matched_dynamic.insert(dyn_cluster_index);
		}
	}
	// And finally add any new dynamic communities
	DynamicClustering::const_iterator dit;
	for( dit = fresh.begin() ; dit != fresh.end(); dit++ )
	{
		m_dynamic.push_back(*dit);
	}
	
	return true;
}
Пример #12
0
int main(void) {
    
    bst_node_type *head;
    data_item_type *item;
    bst_stats_type stats;
    long value;
    char buffer[2048];  
    size_t size;
    char **args;
    int arg_count;
    int i;



    // loop forever receiving command strings from STDIN.
    while (1) {

        size=getline(buffer, sizeof(buffer));

        // ignore that a blank line was entered
        if (size==0)
            continue;

        // break the command into an array 
        arg_count=parse_command(buffer, '/', &args);

        if (arg_count == -1)
            continue;
        
        // add a new element to the database
        if (args[0][0]=='a' && arg_count==2 ) {

            // if the string to add is less than 10 chars, ignore the add command
            if (cgc_strlen(args[1]) < 10) {

                free(args);
                continue;
            }

            item=calloc(1, sizeof(data_item_type));

            if (!item) {

                printf("Unable to allocate memory\n");
                return(-1);
            }

            strncpy(item->name, args[1], sizeof(item->name)-1);
            item->next = 0;

            insert_node(&head, item, make_key_from_name);

        }
        // search for elements of the database
        else if (args[0][0]=='f' && arg_count==2) {

            find_matches(head, arg_count, args);

        }
        // delete an element from the database
        else if (args[0][0]=='d' && arg_count==2) {

            delete_matches(&head, arg_count, args);

        }
        // time to cgc_exit
        else if (args[0][0]=='x') {

            return(0);
        }
        // walk the database and show all entries
        else if (args[0][0]=='w' ) {

            walk_tree(head);
        }
        else if (args[0][0]=='s' ) {

            // clear the stats
            bzero(&stats, sizeof(stats));

            count_bst_stats(head, &stats);

            printf("# of Nodes: @d\n", stats.node_count);
            printf("\% left nodes: @d\n", stats.percent_left);
            printf("\% right nodes: @d\n", stats.percent_right);

        }
        
        free(args);
    }
    int
    test() {
        vi_t rin, rout;
        rin.resize(15);
        rin[0]  = 2;
        rin[1]  = 1;
        rin[2]  = 8;
        rin[3]  = 3;
        rin[4]  = 5;
        rin[5]  = 3;
        rin[6]  = 5;
        rin[7]  = 3;
        rin[8]  = 1;
        rin[9]  = 1;
        rin[10] = 1;
        rin[11] = 1;
        rin[12] = 3;
        rin[13] = 8;
        rin[14] = 6;

        compress_ranges(rin, rout);

        printf("Indexes: ");
        for (size_t i = 0; i < rin.size(); ++i) {
            printf("%4d", i);
        }
        printf("\n");

        printf("rin:     ");
        for (size_t i = 0; i < rin.size(); ++i) {
            printf("%4d", rin[i]);
        }
        printf("\n");

        printf("rout:    ");
        for (size_t i = 0; i < rout.size(); ++i) {
            printf("%4d", rout[i]);
        }
        printf("\n");

        printf("Ranges   ");
        for (size_t i = 0; i < rout.size(); ) {
            printf("%4d(%2d)", i, rout[i]-i);
            i = rout[i];
        }
        printf("%4d", rout.size());
        printf("\n");

        const char *s1 = "the quick brown fox huffs and puffs cats and runs and enthusiastically jumps over the lazy dogs";
        const char *s2 = "it's raining enthusiastically cats and dogs";
        vpii_t out;
        vpiui_t sh;
        int bsz = 12;

        find_matches(s1, s2, bsz, out, sh);

        for (size_t i = 0; i < out.size(); ++i) {
            printf("%.*s: %d, %d\n", bsz, s2+i, out[i].first, out[i].second);
        }

        printf("hash(e quick brow) == %u\n", get_hash("e quick brow", 12));
        printf("hash(enthusiastic) == %u\n", get_hash("enthusiastic", 12));
        return 0;
    }
Пример #14
0
// Thread start function
static void * thread_start(void *arg) {
    struct thread_info *tinfo = (struct thread_info *) arg;
    return (void *) find_matches(tinfo->start, tinfo->bsize, tinfo->pattern);
}
Пример #15
0
int
main (int argc, char *argv[])
{
  WispObject *database;
  int do_long_listing = 0;
  int matches_found = 0;
  int arguments_found = 0;
  char *database_filename = (char *)NULL;

  if (strcmp (argv[0], "rolodex") == 0)
    {
      database_filename = getenv ("ROLODEX");
      if (database_filename == (char *)NULL)
	database_filename = rolodex_file;
    }
  else
    {
      struct passwd *entry;

      entry = getpwuid (getuid ());
      if (entry)
	{
	  database_filename = (char *) xmalloc
	    (strlen (user_file_template) + strlen (entry->pw_dir) + 4);

	  sprintf (database_filename, user_file_template, entry->pw_dir);
	}
    }

  if (!database_filename)
    {
      fprintf (stderr, "Who are you?\n");
      return (-1);
    }

  database = read_database (database_filename);

  while (--argc)
    {
      char *arg = *++argv;

      if (strcmp (arg, "-l") == 0)
	{
	  do_long_listing = 1;
	}
      else
	{
	  WispObject *matches;

	  arguments_found++;
	  matches = find_matches (database, "name:", arg);
	  if (matches != NIL)
	    {
	      matches_found += list_length (matches);
	      print_entries (stdout, matches, do_long_listing);
	    }

	  matches = find_matches (database, "email:", arg);
	  if (matches != NIL)
	    {
	      matches_found += list_length (matches);
	      print_entries (stdout, matches, do_long_listing);
	    }

	  matches = find_matches (database, "e-mail:", arg);
	  if (matches != NIL)
	    {
	      matches_found += list_length (matches);
	      print_entries (stdout, matches, do_long_listing);
	    }
	}
    }

  if (!arguments_found)
    {
      /* Just find birthdays for today's date. */
      WispObject *matches;
      char todays_date[20], yesterdays_date[20], tomorrows_date[20];
      time_t ticks;
      struct tm *now;

      ticks = (time_t)time ((time_t *)NULL);
      now = localtime (&ticks);

      sprintf (todays_date, "%02d/%02d", 1 + now->tm_mon, now->tm_mday);

      ticks -= 60 * 60 * 24;
      now = localtime (&ticks);
      sprintf (yesterdays_date, "%02d/%02d", 1 + now->tm_mon, now->tm_mday);

      ticks += 2 * (60 * 60 * 24);
      now = localtime (&ticks);
      sprintf (tomorrows_date, "%02d/%02d", 1 + now->tm_mon, now->tm_mday);

      matches = find_date_matches (database, "birthday:", todays_date);
      if (matches != NIL)
	{
	  matches_found += list_length (matches);
	  print_entries (stdout, matches, do_long_listing);
	}

      matches = find_date_matches (database, "birthday:", yesterdays_date);
      if (matches != NIL)
	{
	  matches_found += list_length (matches);
	  print_entries (stdout, matches, do_long_listing);
	}

     matches = find_date_matches (database, "birthday:", tomorrows_date);
     if (matches != NIL)
       {
	 matches_found += list_length (matches);
	 print_entries (stdout, matches, do_long_listing);
       }
    }

  return (matches_found != 0);
}
Пример #16
0
Файл: jool.c Проект: NICMx/Jool
/**
 * Never fails because there's no point yet.
 */
static int handle_autocomplete(char *junk, int argc, char **argv, void *arg)
{
	struct cmd_option *node = &tree[0];
	long int depth;
	int i;

	/*
	 * Case 1: Suppose the user typed `jool global update m<tab>`:
	 * Bash will query `jool autocomplete 3 global update m`. (`3` being the
	 * index of the incomplete token in the original command.)
	 * At this point, argc = 5, argv = { "autocomplete", "3", "global",
	 * "update", "m" }.
	 *
	 * Case 2: Suppose the command is `jool global update <tab>`:
	 * Bash will query `jool autocomplete 3 global update`.
	 * argc = 4, argv = { "autocomplete", "3", "global", "update" }.
	 *
	 * Case 3: Suppose the command is `jool <tab>`:
	 * Bash will query `jool autocomplete 1`.
	 * argc = 2, argv = { "autocomplete", "1" }.
	 */

	if (argc < 2)
		return 0;

	errno = 0;
	depth = strtol(argv[1], NULL, 10) - 1;
	if (errno)
		return 0;
	argc -= 2;
	argv += 2;
	/*
	 * depth can be argc when the user is tabbing the next token,
	 * without having actually typed any characters.
	 * (Eg. `jool global update <tab>`)
	 */
	if (depth != (argc - 1) && depth != argc)
		return 0;

	/*
	 * At this point,
	 * Case 1: argc = 3, argv = { "global", "update", "m" }, depth = 2.
	 * Case 2: argc = 2, argv = { "global", "update" }, depth = 2.
	 * Case 3: argc = 0, argv = {}, depth = 0.
	 */

	/*
	 * Traverse the intermediate keywords.
	 * (Cases 1 & 2: "global" and "update", Case 3: None.)
	 */
	for (i = 0; i < depth; i++) {
		node = find_matches(node, argv[i]);
		if (!node)
			return 0; /* Prefix does not exist. */
		if (node->next)
			return 0; /* Ambiguous prefix. */

		if (!node->children) {
			node->handle_autocomplete(node->args);
			return 0;
		}

		node = node->children;
	}

	/* Finally print the candidates for the last token. */
	node = find_matches(node, (i < argc) ? argv[i] : "");
	for (; node; node = node->next)
		printf("%s ", node->label);

	return 0;
}