<commit_before>/*
 * Copyright 2014 Open Connectome Project (http://openconnecto.me)
 * Written by <NAME> (<EMAIL>)
 *
 * This file is part of FlashGraph.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <signal.h>
#ifdef PROFILER
#include <gperftools/profiler.h>
#endif

#include "FGlib.h"
#include "ts_graph.h"

using namespace fg;

void print_usage();

void int_handler(int sig_num)
{
#ifdef PROFILER
	if (!graph_conf.get_prof_file().empty())
		ProfilerStop();
#endif
	exit(0);
}

void run_cycle_triangle(FG_graph::ptr graph, int argc, char *argv[])
{
	int opt;
	int num_opts = 0;
	bool fast = false;

	while ((opt = getopt(argc, argv, "f")) != -1) {
		num_opts++;
		switch (opt) {
			case 'f':
				fast = true;
				break;
			default:
				print_usage();
				abort();
		}
	}

	FG_vector<size_t>::ptr triangles;
	if (fast)
		triangles = compute_directed_triangles_fast(graph,
				directed_triangle_type::CYCLE);
	else
		triangles = compute_directed_triangles(graph,
				directed_triangle_type::CYCLE);
	printf("There are %ld cycle triangles\n", triangles->sum());
}

void run_triangle(FG_graph::ptr graph, int argc, char *argv[])
{
	FG_vector<size_t>::ptr triangles;
	triangles = compute_undirected_triangles(graph);
	printf("There are %ld triangles\n", triangles->sum());
}

void run_local_scan(FG_graph::ptr graph, int argc, char *argv[])
{
	int opt;
	int num_opts = 0;
	int num_hops = 1;

	while ((opt = getopt(argc, argv, "H:")) != -1) {
		num_opts++;
		switch (opt) {
			case 'H':
				num_hops = atoi(optarg);
				num_opts++;
				break;
			default:
				print_usage();
				abort();
		}
	}

	FG_vector<size_t>::ptr scan;
	if (num_hops == 1)
		scan = compute_local_scan(graph);
	else if (num_hops == 2)
		scan = compute_local_scan2(graph);
	else {
		fprintf(stderr, "we don't support local scan of more than 2 hops\n");
		exit(1);
	}
	printf("Max local scan is %ld\n", scan->max());<commit_msg>[Graph]: print both max local scan and the vertex ID.<commit_after>/*
 * Copyright 2014 Open Connectome Project (http://openconnecto.me)
 * Written by <NAME> (<EMAIL>)
 *
 * This file is part of FlashGraph.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <signal.h>
#ifdef PROFILER
#include <gperftools/profiler.h>
#endif

#include "FGlib.h"
#include "ts_graph.h"

using namespace fg;

void print_usage();

void int_handler(int sig_num)
{
#ifdef PROFILER
	if (!graph_conf.get_prof_file().empty())
		ProfilerStop();
#endif
	exit(0);
}

void run_cycle_triangle(FG_graph::ptr graph, int argc, char *argv[])
{
	int opt;
	int num_opts = 0;
	bool fast = false;

	while ((opt = getopt(argc, argv, "f")) != -1) {
		num_opts++;
		switch (opt) {
			case 'f':
				fast = true;
				break;
			default:
				print_usage();
				abort();
		}
	}

	FG_vector<size_t>::ptr triangles;
	if (fast)
		triangles = compute_directed_triangles_fast(graph,
				directed_triangle_type::CYCLE);
	else
		triangles = compute_directed_triangles(graph,
				directed_triangle_type::CYCLE);
	printf("There are %ld cycle triangles\n", triangles->sum());
}

void run_triangle(FG_graph::ptr graph, int argc, char *argv[])
{
	FG_vector<size_t>::ptr triangles;
	triangles = compute_undirected_triangles(graph);
	printf("There are %ld triangles\n", triangles->sum());
}

void run_local_scan(FG_graph::ptr graph, int argc, char *argv[])
{
	int opt;
	int num_opts = 0;
	int num_hops = 1;

	while ((opt = getopt(argc, argv, "H:")) != -1) {
		num_opts++;
		switch (opt) {
			case 'H':
				num_hops = atoi(optarg);
				num_opts++;
				break;
			default:
				print_usage();
				abort();
		}
	}

	FG_vector<size_t>::ptr scan;
	if (num_hops == 1)
		scan = compute_local_scan(graph);
	else if (num_hops == 2)
		scan = compute_local_scan2(graph);
	else {
		fprintf(stderr, "we don't support local scan of more than 2 hops\n");
		exit(1);
	}
	std::pair<size_t, off_t> ret = scan->max_val_loc();
	printf("Max local scan is %ld on v%ld\n", ret.first, ret.second);
{'fraction_non_alphanumeric': 0.133912340941224, 'fraction_numerical': 0.007675217127852959, 'mean_word_length': 4.094650205761317, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3728266', 'n_tokens_mistral': 1880, 'n_tokens_neox': 1696, 'n_words': 517}