<commit_before><?hh

const int T_TYPELIST_LT = 398;
const int T_TYPELIST_GT = 399;
const int T_SHAPE = 402;
const int T_NEWTYPE = 403;
const int T_TYPE = 405;
const int T_GROUP = 423;

namespace beatbox\utils;

type SymbolMap = shape(
	'class' => array<string, string>,
	'function' => array<string, string>,
	'constant' => array<string, string>,
	'type' => array<string, string>
);

function empty_symbol_map() : SymbolMap {
	return shape(
		'class' => [],
		'function' => [],
		'constant' => [],
		'type' => []
	);
}

function common_base_dir(Set<string> $dirs) : string {
	assert($dirs->count() > 0);
	$dirs = $dirs->toImmVector();
	if ($dirs->count() == 1) return substr($dirs[0],0,-1);
	$base = '';

	$i = 0;
	while (true) {
		if (strlen($dirs[0]) < $i)
			break;
		$char = $dirs[0][$i];
		$match = true;
		foreach($dirs as $dir) {
			if (strlen($dir) < $i) {
				$match = false;
				break;
			}
			if ($dir[$i] != $char) {
				$match = false;
				break;
			}
		}

		if ($match) {
			$base .= $char;
		} else {
			break;
		}

		$i++;
	}


	$slash_pos = strrpos($base, '/');
	$base = substr($base, 0, $slash_pos);

	return $base;
}

function build_symbol_map(Traversable<string> $directories) : (string, SymbolMap) {
	$map = shape(
		'class' => [],
		'function' => [],
		'constant' => [],
		'type' => []
	);

	$dirs = Set {};
	foreach ($directories as $dir) {
		$dirs[] = realpath($dir).'/';
	}

	$stripped = Set {};
	foreach ($dirs as $d1) {
		$add = $d1;
		foreach ($dirs as $d2) {
			if ($d1 == $d2) continue;
			$len = min(strlen($d1), strlen($d2));<commit_msg>Handle non-existant directories properly<commit_after><?hh

const int T_TYPELIST_LT = 398;
const int T_TYPELIST_GT = 399;
const int T_SHAPE = 402;
const int T_NEWTYPE = 403;
const int T_TYPE = 405;
const int T_GROUP = 423;

namespace beatbox\utils;

type SymbolMap = shape(
	'class' => array<string, string>,
	'function' => array<string, string>,
	'constant' => array<string, string>,
	'type' => array<string, string>
);

function empty_symbol_map() : SymbolMap {
	return shape(
		'class' => [],
		'function' => [],
		'constant' => [],
		'type' => []
	);
}

function common_base_dir(Set<string> $dirs) : string {
	assert($dirs->count() > 0);
	$dirs = $dirs->toImmVector();
	if ($dirs->count() == 1) return substr($dirs[0],0,-1);
	$base = '';

	$i = 0;
	while (true) {
		if (strlen($dirs[0]) < $i)
			break;
		$char = $dirs[0][$i];
		$match = true;
		foreach($dirs as $dir) {
			if (strlen($dir) < $i) {
				$match = false;
				break;
			}
			if ($dir[$i] != $char) {
				$match = false;
				break;
			}
		}

		if ($match) {
			$base .= $char;
		} else {
			break;
		}

		$i++;
	}


	$slash_pos = strrpos($base, '/');
	$base = substr($base, 0, $slash_pos);

	return $base;
}

function build_symbol_map(Traversable<string> $directories) : (string, SymbolMap) {
	$map = shape(
		'class' => [],
		'function' => [],
		'constant' => [],
		'type' => []
	);

	$dirs = Set {};
	foreach ($directories as $dir) {
		$realpath = realpath($dir);
		if ($realpath)
			$dirs[] = $realpath.'/';
	}

	$stripped = Set {};
	foreach ($dirs as $d1) {
		$add = $d1;
		foreach ($dirs as $d2) {
			if ($d1 == $d2) continue;
			$len = min(strlen($d1), strlen($d2));
{'fraction_non_alphanumeric': 0.2152214597629445, 'fraction_numerical': 0.021210230817217717, 'mean_word_length': 3.4479889042995837, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2191199', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1297, 'n_words': 296}