Esempio n. 1
0
	void clstrshortrangehierarchical(coordlist_t& x,
		box_t& box,
		double range,
		clstrrule_t cluster_function, arg_t args,
		clstrlist_t& cluster)
	{
		int n = x.size();
		cluster.clear();
		cluster.resize(n);

		if (box.boxlo.size() == 0) {
			box.boxlo.push_back(0.0);
			box.boxlo.push_back(0.0);
			box.boxlo.push_back(0.0);
		}
		if (box.boxhi.size() == 0) {
			box.boxhi.push_back(0.0);
			box.boxhi.push_back(0.0);
			box.boxhi.push_back(0.0);
		}
            
		CellList cell_list;
		cell_list.clear();
		cell_list.setBox(box.boxlo, box.boxhi);
		cell_list.setInteractionRange(range);
		cell_list.setNeighborStyle(CellList::FULL);

		cluster.clear();
		std::vector<bool> counted(n, false);

		if (cell_list.good()) {
			for(int i=0; i<n; i++) {
				cell_list.insert(i, x[i]);
			}
			for(int i=0; i<n; i++) {
				if(!counted[i]) {
					std::vector<int> cluster_i;
					add2cluster_recursive(i, n, cluster_i,
						counted, cell_list, cluster_function, args);
					cluster.push_back(cluster_i);
				}
			}
		}
		else {
			//std::cerr << "WARNING...\n";
			clstrhierarchical(n, cluster_function, args, cluster);
		}
	}
Esempio n. 2
0
	void clstrhierarchical(int n, clstrrule_t cluster_function, arg_t args, clstrlist_t& cluster)
	{
		assert(n > 0);
		cluster.clear();

		std::vector<bool> counted(n, false);

		for(int i=0; i<n; i++) {
			if(!counted[i]) {
				std::vector<int> cluster_i;
				add2cluster_recursive(
					i, n, cluster_i, counted, cluster_function, args);
				cluster.push_back(cluster_i);
			}
		}
	}
Esempio n. 3
0
int main()
{
    double vec2[] = {10,20,30,40,50,60,70,80,90};

    std::size_t i = 0;

    for(auto p : counted(vec2))
    {
        assert(i == p.count());
        std::cout << p.count() << ": " << p.value() << std::endl;
        assert(vec2[i] == p.value());

        i++;
    }

    assert(i == 9);

    return 0;
}
Esempio n. 4
0
void readKeyValue(const char *&from, const char *end) {
	if (!skipJunk(from, end)) return;

	if (*from != '"') throw Exception(QString("Expected quote before key name!"));
	const char *nameStart = ++from;
	while (from < end && ((*from >= 'a' && *from <= 'z') || (*from >= 'A' && *from <= 'Z') || *from == '_' || (*from >= '0' && *from <= '9'))) {
		++from;
	}

	if (from == nameStart) throw Exception(QString("Expected key name!"));
	QByteArray varName = QByteArray(nameStart, int(from - nameStart));
	for (const char *t = nameStart; t + 1 < from; ++t) {
		if (*t == '_') {
			if (*(t + 1) == '_') throw Exception(QString("Bad key name: %1").arg(QLatin1String(varName)));
			++t;
		}
	}

	if (from == end || *from != '"') throw Exception(QString("Expected quote after key name in key '%1'!").arg(QLatin1String(varName)));
	++from;

	if (!skipJunk(from, end)) throw Exception(QString("Unexpected end of file in key '%1'!").arg(QLatin1String(varName)));
	if (*from != '=') throw Exception(QString("'=' expected in key '%1'!").arg(QLatin1String(varName)));

	if (!skipJunk(++from, end)) throw Exception(QString("Unexpected end of file in key '%1'!").arg(QLatin1String(varName)));
	if (*from != '"') throw Exception(QString("Expected string after '=' in key '%1'!").arg(QLatin1String(varName)));

	QByteArray varValue;
	const char *start = ++from;
	QVector<QByteArray> tagsList;
	while (from < end && *from != '"') {
		if (*from == '\n') {
			throw Exception(QString("Unexpected end of string in key '%1'!").arg(QLatin1String(varName)));
		}
		if (*from == '\\') {
			if (from + 1 >= end) throw Exception(QString("Unexpected end of file in key '%1'!").arg(QLatin1String(varName)));
			if (*(from + 1) == '"' || *(from + 1) == '\\' || *(from + 1) == '{') {
				if (from > start) varValue.append(start, int(from - start));
				start = ++from;
			} else if (*(from + 1) == 'n') {
				if (from > start) varValue.append(start, int(from - start));

				varValue.append('\n');

				start = (++from) + 1;
			}
		} else if (*from == '{') {
			if (from > start) varValue.append(start, int(from - start));

			const char *tagStart = ++from;
			while (from < end && ((*from >= 'a' && *from <= 'z') || (*from >= 'A' && *from <= 'Z') || *from == '_' || (*from >= '0' && *from <= '9'))) {
				++from;
			}
			if (from == tagStart) throw Exception(QString("Expected tag name in key '%1'!").arg(QLatin1String(varName)));
			QByteArray tagName = QByteArray(tagStart, int(from - tagStart));

			if (from == end || (*from != '}' && *from != ':')) throw Exception(QString("Expected '}' or ':' after tag name in key '%1'!").arg(QLatin1String(varName)));

			LangTags::const_iterator i = tags.constFind(tagName);
			if (i == tags.cend()) {
				i = tags.insert(tagName, tagsOrder.size());
				tagsOrder.push_back(tagName);
			}
			if (0x0020 + *i > 0x007F) throw Exception(QString("Too many different tags in key '%1'").arg(QLatin1String(varName)));

			QString tagReplacer(4, TextCommand);
			tagReplacer[1] = TextCommandLangTag;
			tagReplacer[2] = QChar(0x0020 + *i);
			varValue.append(tagReplacer.toUtf8());
			for (int j = 0, s = tagsList.size(); j < s; ++j) {
				if (tagsList.at(j) == tagName) throw Exception(QString("Tag '%1' double used in key '%2'!").arg(QLatin1String(tagName)).arg(QLatin1String(varName)));
			}
			tagsList.push_back(tagName);

			if (*from == ':') {
				start = ++from;
				
				QVector<QString> &counted(keysCounted[varName][tagName]);
				QByteArray subvarValue;
				bool foundtag = false;
				while (from < end && *from != '"' && *from != '}') {
					if (*from == '|') {
						if (from > start) subvarValue.append(start, int(from - start));
						counted.push_back(QString::fromUtf8(subvarValue));
						subvarValue = QByteArray();
						foundtag = false;
						start = from + 1;
					}
					if (*from == '\n') {
						throw Exception(QString("Unexpected end of string inside counted tag '%1' in '%2' key!").arg(QLatin1String(tagName)).arg(QLatin1String(varName)));
					}
					if (*from == '\\') {
						if (from + 1 >= end) throw Exception(QString("Unexpected end of file inside counted tag '%1' in '%2' key!").arg(QLatin1String(tagName)).arg(QLatin1String(varName)));
						if (*(from + 1) == '"' || *(from + 1) == '\\' || *(from + 1) == '{' || *(from + 1) == '#') {
							if (from > start) subvarValue.append(start, int(from - start));
							start = ++from;
						} else if (*(from + 1) == 'n') {
							if (from > start) subvarValue.append(start, int(from - start));

							subvarValue.append('\n');

							start = (++from) + 1;
						}
					} else if (*from == '{') {
						throw Exception(QString("Unexpected tag inside counted tag '%1' in '%2' key!").arg(QLatin1String(tagName)).arg(QLatin1String(varName)));
					} else if (*from == '#') {
						if (foundtag) throw Exception(QString("Replacement '#' double used inside counted tag '%1' in '%2' key!").arg(QLatin1String(tagName)).arg(QLatin1String(varName)));
						foundtag = true;
						if (from > start) subvarValue.append(start, int(from - start));
						subvarValue.append(tagReplacer.toUtf8());
						start = from + 1;
					}
					++from;
				}
				if (from >= end) throw Exception(QString("Unexpected end of file inside counted tag '%1' in '%2' key!").arg(QLatin1String(tagName)).arg(QLatin1String(varName)));
				if (*from == '"') throw Exception(QString("Unexpected end of string inside counted tag '%1' in '%2' key!").arg(QLatin1String(tagName)).arg(QLatin1String(varName)));

				if (from > start) subvarValue.append(start, int(from - start));
				counted.push_back(QString::fromUtf8(subvarValue));

				if (counted.size() > MaxCountedValues) {
					throw Exception(QString("Too many values inside counted tag '%1' in '%2' key!").arg(QLatin1String(tagName)).arg(QLatin1String(varName)));
				}
			}
			start = from + 1;
		}
		++from;
	}
	if (from >= end) throw Exception(QString("Unexpected end of file in key '%1'!").arg(QLatin1String(varName)));
	if (from > start) varValue.append(start, int(from - start));

	if (!skipJunk(++from, end)) throw Exception(QString("Unexpected end of file in key '%1'!").arg(QLatin1String(varName)));
	if (*from != ';') throw Exception(QString("';' expected after \"value\" in key '%1'!").arg(QLatin1String(varName)));

	skipJunk(++from, end);

	if (varName == "direction") {
		throw Exception(QString("Unexpected value for 'direction' in key '%1'!").arg(QLatin1String(varName)));
	} else if (!LNG_EQUALS_PART(varName, 0, 4, "lng_")) {
		throw Exception(QString("Bad key '%1'!").arg(QLatin1String(varName)));
	} else if (keys.constFind(varName) != keys.cend()) {
		throw Exception(QString("Key '%1' doubled!").arg(QLatin1String(varName)));
	} else {
		keys.insert(varName, QString::fromUtf8(varValue));
		keysTags.insert(varName, tagsList);
		keysOrder.push_back(varName);
	}
}
Esempio n. 5
0
        0x0000                              /* ram */
    },
    /* windows */
    {
        NULL,
        NULL,
        NULL
    }
};

static const struct chip_device_desc_t unifi_device_desc_v1 =
{
    { FALSE, 0xf0ff, 0x1001, 0x01 },        /* UF105x R01 */
    "UF105x",
    "UniFi-1",
    counted(init_vals_v1),                  /* init */
    counted(reset_program_v1_or_v2),        /* reset_prog */
    &unifi_device_regs_v1,                  /* regs */
    {
        TRUE,                               /* has_flash    */
        TRUE,                               /* has_ext_sram */
        FALSE,                              /* has_rom      */
        FALSE,                              /* has_bt       */
        TRUE,                               /* has_wlan */
    },
    counted(unifi_map_address_v1_v2),       /* map */
    /* prog_offset */
    {
        0x00100000,                         /* ram */
        0x00000000,                         /* rom (invalid) */
        0x00000000,                         /* flash */