kClistCore.c
void kcore(sparse* g,unsigned kmax){
	unsigned i,j,r=0,n=g->n,k=kmax-1;
	keyvalue kv;
	unsigned c=0;//the core number
	bheap *heap=mkheap(g);
	g->rank=malloc(g->n*sizeof(unsigned));
	g->map=malloc(g->n*sizeof(unsigned));
	for (i=0;i<g->n;i++){
		kv=popmin(heap);
		if (kv.value>c){
			c=kv.value;
		}
		if (c<k){//remove node with core value less than kmax-1
			g->rank[kv.key]=-1;
			n--;
		}
		else{
			g->map[n-(++r)]=kv.key;
			g->rank[kv.key]=n-r;
		}
		for (j=g->cd0[kv.key];j<g->cd0[kv.key+1];j++){
			update(heap,g->adj0[j]);
		}
	}
	freeheap(heap);
	free(g->d0);
	free(g->cd0);
	free(g->adj0);
	g->core=c;
	g->n2=n;
}
//computing degeneracy ordering and core value
computing degeneracy ordering and core value
computing degeneracy ordering and core value
void kcore(sparse* g,unsigned kmax){
	unsigned i,j,r=0,n=g->n,k=kmax-1;
	keyvalue kv;
	unsigned c=0;
	bheap *heap=mkheap(g);
	g->rank=malloc(g->n*sizeof(unsigned));
	g->map=malloc(g->n*sizeof(unsigned));
	for (i=0;i<g->n;i++){
		kv=popmin(heap);
		if (kv.value>c){
			c=kv.value;
		}
		if (c<k){
			g->rank[kv.key]=-1;
			n--;
		}
		else{
			g->map[n-(++r)]=kv.key;
			g->rank[kv.key]=n-r;
		}
		for (j=g->cd0[kv.key];j<g->cd0[kv.key+1];j++){
			update(heap,g->adj0[j]);
		}
	}
	freeheap(heap);
	free(g->d0);
	free(g->cd0);
	free(g->adj0);
	g->core=c;
	g->n2=n;
}
void kcore ( sparse * g , unsigned kmax ) { unsigned i , j , r = 0 , n = g -> n , k = kmax - 1 ; keyvalue kv ; unsigned c = 0 ; bheap * heap = mkheap ( g ) ; g -> rank = malloc ( g -> n * sizeof ( unsigned ) ) ; g -> map = malloc ( g -> n * sizeof ( unsigned ) ) ; for ( i = 0 ; i < g -> n ; i ++ ) { kv = popmin ( heap ) ; if ( kv . value > c ) { c = kv . value ; } if ( c < k ) { g -> rank [ kv . key ] = -1 ; n -- ; } else { g -> map [ n - ( ++ r ) ] = kv . key ; g -> rank [ kv . key ] = n - r ; } for ( j = g -> cd0 [ kv . key ] ; j < g -> cd0 [ kv . key + 1 ] ; j ++ ) { update ( heap , g -> adj0 [ j ] ) ; } } freeheap ( heap ) ; free ( g -> d0 ) ; free ( g -> cd0 ) ; free ( g -> adj0 ) ; g -> core = c ; g -> n2 = n ; }
computing degeneracy ordering and core value
computing degeneracy ordering and core value
//the core number //remove node with core value less than kmax-1