multitree::multitree - create


template <class k, class t, class compare, class less>
multitree<,t,compare,less>::multitree()

This constructor creates a multitree.

Notes

A multitree is a multiset with an extra comparer that compares the key (k) to the datatype (t). It then supports searches by that key (by k in other words). The comparers of a tree are shown in the following example.

import std.core;
import iplusplus;
using namespace standard;

struct t
{
	int i;
	string s;

	t() {}

	t(int _i, const string& _s) : i(_i), s(_s) {}
};

std::ostream& operator<<(std::ostream& s, const t& _t)
{
	s << "(" << _t.i << "," << _t.s << ")";
	return s;
}

bool operator<(const t& a, const t& b)
{
	if (a.i < b.i) return true;
	return false;
}

struct tree_compare
{
	int operator()(const int& key, const t& type) const
	{
		if (key < type.i) return -1;
		if (type.i < key) return 1;
		return 0;
	}
};

int main()
{
    multitree<int, t, tree_compare> multitree;
    multitree << t(0, "hello") << t(0, "world") << t(1, "world");
    std::cout << multitree << "\n";
    std::cout << multitree[0] << "\n";
}

The output of the program is shown below.

{(0,hello),(0,world),(1,world)}
{(0,hello),(0,world)}

The class tree_compare contains a function operator that performs int to t comparisons. Note that this comparer returns <0 when the int is less that the t, >0 when the int is greater than the t and 0 when the int is equal to the t. This differs from the base set class which works off the less than operator for t.