示例#1
0
文件: rules.c 项目: alga/lines
int pop_new(void)
{
    int i,j,k, nr_free, rnd;
    GList *free_cells = NULL, *cell = NULL;

    for(i = 0; i < SIZE; i++)
	for(j = 0; j < SIZE; j++)
	    if(!field[i][j])
		free_cells = g_list_append( free_cells, 
					     (gpointer)(i << 16 | j));
    for(k = 0; k < POP_BALLS; k++)  {
	nr_free = g_list_length(free_cells);
	if(nr_free <= POP_BALLS)
	    return FALSE;
	if (next_pops[k].c && !field[next_pops[k].x][next_pops[k].y]) {
	    /* we have something planned && the place isn't taken yet */
	    field[next_pops[k].x][next_pops[k].y] = next_pops[k].c;
	    put_child(next_pops[k].x, next_pops[k].y);
	} else if (next_pops[k].c) {
	    /* Oops.  The place has already been taken */
	    rnd = (int)(((double)nr_free * rand() ) / (RAND_MAX + 1.0));
	    cell = g_list_nth( free_cells, 
			       rnd);
	    i = (unsigned)(cell->data) >> 16;
	    j = (unsigned)(cell->data) & 0xFFFF;
	    free_cells = g_list_remove_link(free_cells, cell);
	    g_list_free(cell);
	    field[i][j] = next_pops[k].c;
	    put_child(i,j);
	}
	next_pops[k].x = next_pops[k].y = next_pops[k].c = 0;
    }
//增加一个新的CHILD,当然里面全部数据为NULL
int ZCE_Conf_PropertyTree::new_child(const std::string &path_str,
                                     const std::string &new_child_name)
{
    PROPERTY_TREE_NODE null_node;
    return put_child(path_str, new_child_name, null_node);

}
示例#3
0
int dictionary_insert(struct dictionary *dict, const wchar_t *word)
{
	assert(dict != NULL);
	struct dictionary *node = NULL;

	/* Pierwsze slowo */
	if (dict->children_size == 0)
	{
		for(node = dict; *word; node = *node->children)
		{
			put_child(node, create_node(*word));
			word++;
		}
		put_child(node, create_node(NULL_MARKER));
		return 1;
	}
	node = dict;
	struct dictionary *found = NULL;
	while (find_child(node, &found, *word) && *word)
	{
		node = found;
		word++;
	}
	if (*word == L'\0')
	{
		if (find_child(node, &found, NULL_MARKER))
			return 0;
		put_child(node, create_node(NULL_MARKER));
	}
	else
	{
		struct dictionary *tmp = create_node(*word);
		put_child(node, tmp);
		dictionary_insert(tmp, ++word);
	}
	return 1;
}
示例#4
0
	void send(const Message& message) override
	{
		thread_local pid_t  tid = syscall(SYS_gettid);	// cache tid (reduce syscalls)
		thread_local string prg = message.get<string>("prg", string());

		if (message.get<int>("priority", LogDebug::priority) > priority)
			return;

		auto messagePtr = make_unique<Message>(message);

		for (auto& kv : base)
			messagePtr->put_child(kv.first, kv.second);

		//messagePtr->put("timestamp", chrono::steady_clock::now().time_since_epoch());

		messagePtr->put("tid", tid);

		if (!prg.empty())
			messagePtr->put("prg", prg);

		pushMessage(move(messagePtr));
	}
示例#5
0
/**
 * Funkcja pomocnicza dictionary_load.
 * Zwraca na 'dict' wskaznik do powstałego słownika, utworzonego na
 * podstawie pliku 'stream'.
 * @param[in,out] dict Słownik.
 * @param[in] stream Plik.
 * @return <0 jeśli operacja się nie powiedzie, 0 w p.p
 */
static int deserialize(struct dictionary **dict, FILE* stream)
{
	int valid = 0;
	wchar_t key;
	if (fscanf(stream, "%1ls", &key) != EOF)
	{
		int size;
		if (fscanf(stream, "%d", &size) != EOF)
		{
			*dict = create_node(key);
			for (int i = 0; i < size; i++)
			{
				struct dictionary *child = NULL;
				valid += deserialize(&child, stream);
				put_child(*dict, child);
			}
		}
	}
	if (ferror(stream))
		valid += -1;
	return valid;
}