<commit_before>/* Fibonacci Heap
 * Copyright 2015 330k
 * https://github.com/330k/
 *
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
function fibonacci_heap(){
	var _top = null;
	var _size = 0;
	var _mergeList = function(i, j){
		if(i === null) return j;
		if(j === null) return i;
		
		var iNext = i.next;
		i.next = j.next;
		i.next.prev = i;
		j.next = iNext;
		j.next.prev = j;

		return i.p > j.p ? i : j;
	};
	
	var enqueue = function(priority, value){
		var newnode = {
			p: priority,
			v: value,
			marked: false,
			rank: 0,
			next: null,
			prev: null,
			firstchild: null
		};
		newnode.next = newnode;
		newnode.prev = newnode;
		
		_top = _mergeList(_top, newnode);
		_size++;
	};
	var dequeue = function(){
		var result = _top.v;
		_size--;
		
		if(_top.next === _top){
			_top = null;
		}else{
			_top.prev.next = _top.next;
			_top.next.prev = _top.prev;
			_top = _top.next;
		}
		
		_top = _mergeList(_top, result.firstchild);
		
		if(_top === null){
			return result;
		}
		
		var ranks = [];
		var roots = [];

		var curr = _top;
		do{
			roots.push(curr);
			curr = curr.next;
		} while(curr !== _top);
		
		for(var i = 0; i < roots.length; i++){
			curr = roots[i];
			while(true){
				if(ranks[curr.rank] === undefined){
					ranks[curr.rank] = curr;
					break;
				}
				var other = ranks[curr.rank];
				ranks[curr.rank] = undefined;
				
				var min, max;
				if(curr.p < other.p){
					min = curr;
					max = other;
				}else{
					min = other;
					max = curr;
				}
				
				min.next.prev = min.prev;
				min.prev.next = min.next;
				
				min.next = min.prev = min;
				max.firstchild = _mergeList(max.firstchild, min);
				
				min.marked = false;
				max.rank++;
				
				curr = max;
			}
			if(curr.p > _top.p){
				_top = curr;
			}
		}
		
		return result;
	};
	var top = function(){
		return _top.v;
	};
	var size = function(){
		return _size;
	};
	
	return {
		name: 'Fibonacci Heap',
		enqueue: enqueue,
		dequeue: dequeue,
		top: top,
		size: size
	};
}<commit_msg>midofy dequeue<commit_after>/* Fibonacci Heap
 * Copyright 2015 330k
 * https://github.com/330k/
 *
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
function fibonacci_heap(){
	var _top = null;
	var _size = 0;
	var _mergeList = function(i, j){
		if(i === null) return j;
		if(j === null) return i;
		
		var iNext = i.next;
		i.next = j.next;
		i.next.prev = i;
		j.next = iNext;
		j.next.prev = j;

		return i.p > j.p ? i : j;
	};
	
	var enqueue = function(priority, value){
		var newnode = {
			p: priority,
			v: value,
			marked: false,
			rank: 0,
			next: null,
			prev: null,
			firstchild: null
		};
		newnode.next = newnode;
		newnode.prev = newnode;
		
		_top = _mergeList(_top, newnode);
		_size++;
	};
	var dequeue = function(){
		var result = _top;
		_size--;
		
		if(_top.next === _top){
			_top = null;
		}else{
			_top.prev.next = _top.next;
			_top.next.prev = _top.prev;
			_top = _top.next;
		}
		
		_top = _mergeList(_top, result.firstchild);
		
		if(_top === null){
			return result.v;
		}
		
		var ranks = [];
		var roots = [];

		var curr = _top;
		do{
			roots.push(curr);
			curr = curr.next;
		} while(curr !== _top);
		
		for(var i = 0; i < roots.length; i++){
			curr = roots[i];
			while(true){
				if(ranks[curr.rank] === undefined){
					ranks[curr.rank] = curr;
					break;
				}
				var other = ranks[curr.rank];
				ranks[curr.rank] = undefined;
				
				var min, max;
				if(curr.p < other.p){
					min = curr;
					max = other;
				}else{
					min = other;
					max = curr;
				}
				
				min.next.prev = min.prev;
				min.prev.next = min.next;
				
				min.next = min.prev = min;
				max.firstchild = _mergeList(max.firstchild, min);
				
				min.marked = false;
				max.rank++;
				
				curr = max;
			}
			if(curr.p > _top.p){
				_top = curr;
			}
		}
		
		return result.v;
	};
	var top = function(){
		return _top.v;
	};
	var size = function(){
		return _size;
	};
	
	return {
		name: 'Fibonacci Heap',
		enqueue: enqueue,
		dequeue: dequeue,
		top: top,
		size: size
	};
}
{'fraction_non_alphanumeric': 0.15784384819917816, 'fraction_numerical': 0.0062847474014986705, 'mean_word_length': 2.240407204385278, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '608970', 'n_tokens_mistral': 2035, 'n_tokens_neox': 1619, 'n_words': 389}