Ejemplo n.º 1
0
void BenchNTL2(const char *file, Stream& out) {
	FileIn in(file);
	if (!in) {
		out << "Cannot open input file.\n";
		return;
	}

	VectorMap<String, int> map;
	
	for(;;) {
		int c = in.Get();
		if(c < 0) break;
		if(IsAlpha(c) || c == '_') {
			String id;
			id.Cat(c);
			c = in.Get();
			while(c >= 0 && (IsAlNum(c) || c == '_')) {
				id.Cat(c);
				c = in.Get();
			}
			map.GetAdd(id, 0)++;
		}
		else
		if(IsDigit(c))
			do c = in.Get();
			while(c >= 0 && (IsAlNum(c) || c == '.'));
	}

	Vector<int> order = GetSortOrder(map.GetKeys());
	for(int i = 0; i < order.GetCount(); i++)
		out << ~map.GetKey(order[i]) << ": " << map[order[i]] << '\n';
}
Ejemplo n.º 2
0
void Puzzle::Scores()
{
    WithScoreLayout<TopWindow> d;
    CtrlLayoutOK(d, t_("Best scores"));
    d.score.AddColumn(t_("Dimension"));
    d.score.AddColumn(t_("Moves"));
    d.score.ColumnWidths("71 48");
    d.score.NoCursor().NoGrid();
    Vector<int> o = GetSortOrder(score.GetKeys());
    for(int i = 0; i < o.GetCount(); i++)
        d.score.Add(score.GetKey(o[i]), score[o[i]]);
    d.Run();
}
Ejemplo n.º 3
0
void BenchNTL(const char *file) {
	FileIn in(file);
	if (!in) {
		std::cout << "Cannot open input file.\n";
		return;
	}

	VectorMap<String, Vector<int> > map;
	int line = 1;

	for(;;) {
		int c = in.Get();
		if(c < 0) break;
		if(IsAlpha(c) || c == '_') {
			String id;
			id.Cat(c);
			c = in.Get();
			while(c >= 0 && (IsAlNum(c) || c == '_')) {
				id.Cat(c);
				c = in.Get();
			}
			map.GetAdd(id).Add(line);
		}
		else
		if(IsDigit(c))
			do c = in.Get();
			while(c >= 0 && (IsAlNum(c) || c == '.'));
		if(c == '\n')
			++line;
	}

	Vector<int> order = GetSortOrder(map.GetKeys());
#ifndef NO_OUTPUT
	for(int i = 0; i < order.GetCount(); i++) {
		std::cout << ~map.GetKey(order[i]) << ": ";
		const Vector<int>& l = map[order[i]];
		for(int i = 0; i < l.GetCount(); i++) {
			if(i) std::cout << ", ";
			std::cout << l[i];
		}
		std::cout << '\n';
	}
#endif
}
Ejemplo n.º 4
0
int main(int argc, const char *argv[])
{
	int n;
	VectorMap<String, int> map;
	Cout() << "   lines   words   bytes file\n";
	int total_lines = 0;
	int total_words = 0;
	int total_bytes = 0;
	for(int i = 1; i < argc; i++) {
		String f = LoadFile(argv[i]);
		int lines = 0;
		int words = 0;
		const char *q = f;
		for(;;) {
			int c = *q;
			if(IsAlpha(c)) {
				const char *b = q++;
				while(IsAlNum(*q)) q++;
				map.GetAdd(String(b, q), 0)++;
				words++;
			}
			else {
				if(!c) break;
				if(c == '\n')
					++lines;
				q++;
			}
		}
		Cout() << Format("%8d%8d%8d %s\n", lines, words, f.GetCount(), argv[i]);
		total_lines += lines;
		total_words += words;
		total_bytes += f.GetCount();
	}
	Vector<int> order = GetSortOrder(map.GetKeys());
#ifndef NOOUTPUT
	Cout() << Format("--------------------------------------%8d%8d%8d total\n", total_lines, total_words, total_bytes);

	for(int i = 0; i < order.GetCount(); i++)
		Cout() << map.GetKey(order[i]) << ": " << map[order[i]] << '\n';
#endif
	return 0;
}
Ejemplo n.º 5
0
ValueMap::ValueMap(const VectorMap<Value, Value>& m, int deep)
{
	Data& d = Create();
	d.key = clone(m.GetKeys());
	d.value = ValueArray(m.GetValues(), 0);
}