Search-ContextGraph

 view release on metacpan or  search on metacpan

ContextGraph.xs  view on Meta::CPAN

#define  DEFAULT_CAPACITY 2

  
MODULE = Search::ContextGraph		PACKAGE = Search::ContextGraph		

INCLUDE: const-xs.inc

void
free_node(node)
	Node *	node

Edge *
new_edge(edge, sink, weight)
	Edge *	edge
	long	sink
	float	weight

Graph *
new_graph(graph, capacity = DEFAULT_CAPACITY, activationThreshold = 1, collectionThreshold = 1, maxDepth = 100000000)
	Graph *	graph
	long	capacity
	float	activationThreshold
	float	collectionThreshold
	long 	maxDepth

Node *
new_node(node, type, capacity=DEFAULT_CAPACITY)
	Node *	node
	int 	type
	long	capacity

MODULE = Search::ContextGraph	PACKAGE = Search::ContextGraph::Graph 

Node *
add_node(graph, id, type, capacity=DEFAULT_CAPACITY)
	Graph *	graph
	long	id
	int	type
	long	capacity


void
collect_results(graph)
		Graph * graph
		
	PREINIT:	
		AV * list;
		AV *entry;
		SV *undef;
		Edge *result;
		int startSize;
		int i;
		int result_count;
		
    INIT:
    	result_count = 0;
    	undef = (SV*) &PL_sv_undef;
		list =  (AV *) sv_2mortal((SV *)newAV());
		startSize = 64;
		
    PPCODE:
		result = collect_results(graph);
		for (i = 0; result[i].weight > 0; i++) {
			entry = newAV();
			/* fprintf( stderr, "weight %ld, %ld, %f \n", i, result[i].sink, result[i].weight);
			*/
			av_push(entry, newSViv(result[i].sink));
			av_push(entry, newSVnv(result[i].weight));
			av_push(list, newRV_noinc((SV *)entry));
			result_count++;
		}
		
		//fprintf( stderr, "result count %ld ", result_count);

		if ( result_count > 0 ) {
			XPUSHs(newRV_noinc((SV *)list));
		} else {
			XPUSHs( undef  );
		}
		free( result );
	
	

int
energize_node(graph, id, energy, isStart)
	Graph *	graph
	int	id
	float	energy
	int isStart

void
preallocate( graph, number )
	Graph * graph
	int number
	
void
reset_graph(graph)
	Graph *	graph

void
free_graph(graph)
	Graph *	graph

Graph *
new(CLASS, startingEnergy = 100, activationEnergy = 1, collectionEnergy = 1, maxDepth = 100000000)
	char *CLASS = NO_INIT
	float startingEnergy;
	float activationEnergy;
	float collectionEnergy;
	long maxDepth;
	
    PROTOTYPE: $;$$$$
    CODE:
		/* Zero((void*)&RETVAL, sizeof(RETVAL), char); */
	RETVAL = malloc(sizeof(Graph));
		/* fprintf( stderr, "NEW called: %p\n", RETVAL ); */
		new_graph(
			(Graph *)RETVAL, DEFAULT_CAPACITY,
			 activationEnergy, collectionEnergy, maxDepth);
    OUTPUT:
	RETVAL



( run in 0.991 second using v1.01-cache-2.11-cpan-5511b514fd6 )