<commit_before>var colors = ["green", "orange", "blue", "purple", "brown", "steelblue"]
var color_i = 0;

function Block(prev, time, miner) {
	this._prev = function() {
		return prev;
	}

	if (miner)
		this.credit = miner.id;
	else
		this.credit = false;

	this.id = ConsensusState.prototype.rand();
	this.time = time;
	this.color = colors[color_i]
	if (typeof this.color == "undefined") {
		color_i = 0;
		this.color = colors[color_i]
	} else {
		color_i++;
	}

	if (prev) {
		this.h = prev.h + 1;
		this.prev = prev.id;
		this.difficulty = prev.difficulty;
		this.work = prev.work + prev.difficulty;

		if (!(this.h % this.difficulty_adjustment_period)) {
			this.difficultyAdjustment()
		}
	}
	else {
		this.h = 0;
		this.prev = false;
		this.difficulty = 600000;
		//this.difficulty = 3000;
		this.work = 0;
	}
}

Block.prototype = {
	target_avg_between_blocks: 10 * 60 * 1000,
	difficulty_adjustment_period: 2016,

	difficultyAdjustment: function() {
		var total = 0;
		var last = this.time;
		var cur = this._prev();

		for (var i=0;i<this.difficulty_adjustment_period;i++) {
			total += last - cur.time;
			last = cur.time;
			cur = cur._prev()
		}
		var avg = total / this.difficulty_adjustment_period;

		var old = this.difficulty;
		this.difficulty *= this.target_avg_between_blocks / avg;

		console.log("(h=" + this.h + ") difficulty adjustment " + (this.target_avg_between_blocks / avg) + "x")
	}
}

function PrevTransition(bid) {
	this.id = bid;
}

PrevTransition.prototype = ConsensusMapObject;

function OrphanBlock(b) {
	this.id = b.id;
	this.b = b;
}

OrphanBlock.prototype = ConsensusMapObject;

function OrphanBlockByPrev(b) {
	this.id = b.id;
	this.b = b;
	this.bucket = b._prev().id;
}<commit_msg>stop wasteful closures<commit_after>var colors = ["green", "orange", "blue", "purple", "brown", "steelblue"]
var color_i = 0;

function Block(prev, time, miner) {
	this.__prev = prev;

	if (miner)
		this.credit = miner.id;
	else
		this.credit = false;

	this.id = ConsensusState.prototype.rand();
	this.time = time;
	this.color = colors[color_i]
	if (typeof this.color == "undefined") {
		color_i = 0;
		this.color = colors[color_i]
	} else {
		color_i++;
	}

	if (prev) {
		this.h = prev.h + 1;
		this.prev = prev.id;
		this.difficulty = prev.difficulty;
		this.work = prev.work + prev.difficulty;

		if (!(this.h % this.difficulty_adjustment_period)) {
			this.difficultyAdjustment()
		}
	}
	else {
		this.h = 0;
		this.prev = false;
		this.difficulty = 600000;
		//this.difficulty = 3000;
		this.work = 0;
	}
}

Block.prototype = {
	target_avg_between_blocks: 10 * 60 * 1000,
	difficulty_adjustment_period: 2016,

	difficultyAdjustment: function() {
		var total = 0;
		var last = this.time;
		var cur = this._prev();

		for (var i=0;i<this.difficulty_adjustment_period;i++) {
			total += last - cur.time;
			last = cur.time;
			cur = cur._prev()
		}
		var avg = total / this.difficulty_adjustment_period;

		var old = this.difficulty;
		this.difficulty *= this.target_avg_between_blocks / avg;

		console.log("(h=" + this.h + ") difficulty adjustment " + (this.target_avg_between_blocks / avg) + "x")
	},
	_prev: function() {
		return this.__prev;
	}
}

function PrevTransition(bid) {
	this.id = bid;
}

PrevTransition.prototype = ConsensusMapObject;

function OrphanBlock(b) {
	this.id = b.id;
	this.b = b;
}

OrphanBlock.prototype = ConsensusMapObject;

function OrphanBlockByPrev(b) {
	this.id = b.id;
	this.b = b;
	this.bucket = b._prev().id;
}
{'fraction_non_alphanumeric': 0.15100864553314122, 'fraction_numerical': 0.016714697406340056, 'mean_word_length': 3.5611038107752955, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6089354', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1321, 'n_words': 276}