#include<stk.h>
#include<LINK/stkWrapper/LINK_STk.h>
#include<LINK/stkWrapper/Wrapper.h>
#include<LINK/basic/Set.h>
#include<LINK/graph/Vertex.h>
#include<LINK/graph/Edge.h>
#include<LINK/graph/Graph.h>
#include<LINK/algorithm/Algorithms.h>

PRIMITIVE MinWeightPerfectMatchingWrapper(SCM g)
{
	Graph *gr;
	if (!(gr = getGraph(g)))   // see src/stkWrapper/stkUtils.cc
		Err("min-weight-perfect-matching: expected <graph*> ", g);

	Set<Edge*> result = MinWeightPerfectMatching(gr);
	Set<Edge*>* new_copy = new Set<Edge*>(result);

	return STk_make_CXXwrapper(
		Wrapper<Set<Edge*> >::type,	// stkWrapper/Wrapper.h
		Wrapper<Set<Edge*> >::name,
		(void *) new_copy,	
		LINK_DYNAMIC);		// tells STk's garbage collector
					// to delete new_copy when the user
					// is finished with it
}

//
// This is what must go into userinit.cc
//
void gen_MinWeightPerfectMatching_Wrapper()
{
        STk_add_new_cpp_primitive("min-weight-perfect-matching", // cmd name
		  tc_subr_1,		// # parms
                  (PRIMITIVE (*)(...))MinWeightPerfectMatchingWrapper);
}
