import std.container, std.stdio, std.typecons;

alias Tuple!(uint, "id") Link;

struct Node1
{
	uint id;
	Link[] links;

	this(uint id)
	{
		this.id = id;
	}

	void addLink(uint l)
	{
		links ~= Link(l);
	}
}

struct Node2
{
	uint id;
	Array!(Link) links;

	this(uint id)
	{
		this.id = id;
	}

	void addLink(uint l)
	{
		links.insert(Link(l));
	}
}

struct Network(Node)
{
	Node[uint] nodes;

	void add(uint i, uint j)
	{
		if((i in nodes) is null)
			nodes[i] = Node(i);
		if((j in nodes) is null)
			nodes[j] = Node(j);

		nodes[i].addLink(j);
		nodes[j].addLink(i);
	}

	void print()
	{
		foreach(k; nodes.keys)
		{
			write("[", k, "]");
			foreach(l; nodes[k].links)
				write(" ", l.id);
			writeln();
		}
		writeln();
	}
}


void main()
{
	auto n1 = Node1(1);
	auto n2 = Node2(2);

	n1.addLink(5);
	n1.addLink(6);
	writeln(n1.links[0].id, "\t", n1.links[1].id);

	n2.addLink(7);
	n2.addLink(8);
	writeln(n2.links[0].id, "\t", n2.links[1].id);

	Network!Node1 net1;
	Network!Node2 net2;

	net1.add(1, 5);
	net1.print();
	net1.add(1, 6);
	net1.print();

	// segfaults on this command
	net2.add(1, 7);
}

